网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

全文最详细的Apache的管理及优化Web(图文详解)-创新互联

目录

成都创新互联10多年成都企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都企业网站建设及推广,对成都地磅秤等多个方面拥有丰富的网站制作经验的网站建设公司。

前言

一、Apache的安装及启用

二、Apache的基本信息 

三、Apache的基本配置及修改 

1、默认发布文件

2、Apache端口修改

3、默认发布目录

三、Apache的访问控制 

1、基于客户端ip的访问控制 

2、基于用户认证 

四、Apache的虚拟主机

五、Apache的语言支持

六、Apache的加密访问


前言

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。可用于提供超文本传输协议,本质上是一个软件。

超文本传输协议:http://,提供该协议的软件一般有:Apache、nginx、stgw、jfe、Tengine,而Apache在网页应用中使用比较广泛。

一、Apache的安装及启用

dnf install httpd.x86_64 -y      dnf安装
systemctl enable --now httpd     开启服务并设定服务位开机启动
firewall-cmd --list-all             查看火墙信息
firewall-cmd --permanent --add-service=http     在火墙中永久开启http访问

firewall-cmd --permanent --add-service=https    在火墙中永久开启https访问
firewall-cmd --reload             刷新火墙使设定生效

二、Apache的基本信息 
服务名称:httpd
配置文件:

/etc/httpd/conf/httpd.conf (主配置文件)

/etc/httpd/conf.d/*.conf(子配置文件)

默认发布目录:/var/www/html
默认发布文件:index.html
默认端口:

80(http)

443 (https)

用户:apache
日志:/etc/httpd/logs

三、Apache的基本配置及修改 

1、默认发布文件

vim /etc/httpd/conf/httpd.conf       编辑主配置文件
DirectoryIndex westos.html index.html      添加默认发布文件westos.html
systemctl restart httpd           重启服务

2、Apache端口修改

vim /etc/httpd/conf/httpd.conf        编辑主配置文件
Listen 8080
firewall-cmd --permanent --add-port=8080/tcp        防火墙设置允许xxxx端口
firewall-cmd --reload        防火墙信息重新加载
systemctl restart httpd        重启httpd服务

3、默认发布目录

mkdir /var/www/westos
mv /var/www/westos /var
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/westos"

Require all granted

systemctl restart httpd

firefox http://192.168.0.11

三、Apache的访问控制  1、基于客户端ip的访问控制 

素材

vim /etc/httpd/conf/httpd.conf        修改的位置

systemctl restart httpd                   每次修改完后都需要重启服务

(1)ip白名单       注意:白名单时,先Deny后Allow才可以,因为顺序颠倒的话,Deny会把Allow给覆盖掉

  Order Deny,Allow
  Allow from ip        
  Deny from All

(2)ip黑名单       注意:黑名单时,先Allow后Deny才可以,因为顺序颠倒的话,Allow会把Deny给覆盖掉  

  Order Allow,Deny
  Allow from All        
  Deny from ip

黑名单:

本机不能访问

白名单:

2、基于用户认证 

vim /etc/httpd/conf/httpd.conf

AuthUserfile /etc/httpd/htpasswdfile                                  ##指定认证文件
AuthName "Please input your name and password"        ##认证提示语
AuthType basic                                                                 ##认证类型
Require user admin                                                          ##允许通过的认证用户 2选1
Require valid-user                                                            ##允许所有用户通过认证 2选1

htpasswd -cm /etc/httpd/htpasswdfile admin         生成认证文件
注意:
当/etc/httpd/htpasswdfile存在那么在添加用户时不要加-c参数否则会覆盖源文件内容

白名单:

只有lee可以访问

四、Apache的虚拟主机

在实际情况中,不可能每访问一个网页就需要一台主机来安装Apache并部署相关环境,虚拟主机实现了同一个ip下有多个站点,即可以通过一个ip来访问多个网页内容。

(1)虚拟主机建立
mkdir /var/www/virutal/westos.org/{news,bbs}/html -p

echo news.westos.org >/var/www/virutal/westos.org/news/html/index.html
echo bbs.westos.org >/var/www/virutal/westos.org/bbs/html/index.html

vim /etc/httpd/conf.d/vhosts.conf

DocumentRoot "/var/www/html"
CustomLog logs/default.log combined


ServerName wenku.westos.com
DocumentRoot "/var/www/westos.com/wenku"
CustomLog logs/wenku.log combined

ServerName news.westos.com
DocumentRoot "/var/www/westos.com/news"
CustomLog logs/news.log combined

测试:

在浏览器中访问以下内容:
firefox http://www.westos.org
firefox http://lee.westos.org
firefox http://linux.westos.org

重启服务

五、Apache的语言支持

php
vim /var/www/html/index.php
phpinfo();
?>

dnf install php -y
systemctl restart httpd
firefox http://192.168.1.10/index.php

cgi
mkdir /var/www/html/cgidir
vim /var/www/html/cgidir/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;

vim /etc/httpd/conf.d/vhost.conf

Options +ExecCGI
AddHandler cgi-script .cgi

firefox http://192.168.1.10/cgidir/index.cgi

wsgi
书写wsgi的测试文件
vim /var/www/html/wsgi/index.wsgi
def application(env, westos):
westos('200 ok',[('Content-Type', 'text/html')])
return [b'hello westos ahhahahahah!']

dnf install python3-mod_wsgi
systemctl restart httpd

vim /etc/httpd/conf.d/vhost

ServerName wsgi.westos.org
WSGIScriptAlias / /var/www/html/wsgi/index.wsgi

php

cgi

首先修改上下文 

找CGI 

实验成功 

wsgi 

最后别忘了给执行权限,因为它是脚本

六、Apache的加密访问

网页上用户的个人信息传输如果不经过加密手段,安全性将会受到极大的威胁,比如说账户密码信息,此时就需要一种加密手段能够给用户信息加密,相当于给用户信息上锁,而这个锁必须是经过专门机构认证的锁,这个锁就相当于私钥,锁的认证信息相当于证书签名文件,生成证书需要私钥和证书签名文件,二者缺一不可。

##安装加密插件
dnf install mod_ssl -y##生成证书

1.command 1
openssl genrsa -out /etc/pki/tls/private/www.westos.com.key 2048 #生成私钥
openssl req -new -key /etc/pki/tls/private/www.westos.com.key \
-out /etc/pki/tls/certs/www.westos.com.csr ##生成证书签名文件
openssl x509 -req -days 365 -in \
/etc/pki/tls/certs/www.westos.com.csr \
-signkey /etc/pki/tls/private/www.westos.com.key \
-out /etc/pki/tls/certs/www.westos.com.crt #生成证书
x509 证书格式
-req 请求
-in 加载签证名称
-signkey /etc/pki/tls/private/www.westos.com.key
2.command 2
openssl req --newkey rsa:2048 \
-nodes -sha256 -keyout /etc/httpd/westos.org.key \
-x509 -days 365 -out /etc/httpd/westos.org.crt

vim /etc/httpd/conf.d/vhost.conf

ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1


ServerName login.westos.com
DocumentRoot "/www/westos.com/login"
CustomLog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key

systemctl restart httpd
^(/.*)$                          ##客户地址栏中输入的地址
%{HTTP_HOST}         ##客户主机
$1                                ##RewriteRule后面跟的第一串字符的值

直接使用方式2 

去访问login.westos,org自动就转到https 

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网站题目:全文最详细的Apache的管理及优化Web(图文详解)-创新互联
文章转载:http://bjjierui.cn/article/dgipis.html

其他资讯