httpd常用配置之虚拟主机
作者:互联网
httpd常用配置
目录切换使用MPM(编辑/etc/httpd/conf.modules.d/00-mpm.conf文件):
\(\color{red}{注:如果apache为编译安装,那么就要编辑/usr/local/apache/conf/httpd.conf}\)
LoadModule mpm_NAME_module modules/mod_mpm_NAME.so
NAME有三种,分别是:
prefork
event
worker
访问控制法则:
法则 | 功能 |
---|---|
Require all granted | 允许所有主机访问 |
Require all deny | 拒绝所有主机访问 |
Require ip IPADDR | 授权指定来源地址的主机访问 |
Require not ip IPADDR | 拒绝指定来源地址的主机访问 |
Require host HOSTNAME | 授权指定来源主机名的主机访问 |
Require not host HOSTNAME | 拒绝指定来源主机名的主机访问 |
IPADDR的类型 | HOSTNAME的类型 |
---|---|
IP:192.168.1.1 Network/mask:192.168.1.0/255.255.255.0 Network/Length:192.168.1.0/24 Net:192.168 | FQDN:特定主机的全名 DOMAIN:指定域内的所有主机 |
注意:httpd-2.4版本默认是拒绝所有主机访问的,所以安装以后必须做显示授权访问
示例:
[root@liu conf]# vim httpd.conf
<Directory "/www/html/aixin">
<RequireAll>
Require all granted
</RequireAll>
</Directory>
虚拟主机:
虚拟主机有三类:
- 相同IP不同端口
- 不同IP相同端口
- 相同IP相同端口不同域名
示例:
相同IP不同端口
#相同IP不同端口
[root@liu conf]# vim httpd.conf
ServerName www.example.com:80 #取消此行注释
# Virtual hosts
Include conf/extra/httpd-vhosts.conf #搜索Include取消此行注释,启用此配置文件
[root@liu conf]# cd extra/
[root@liu extra]# vim httpd-vhosts.conf #修改端口,路径和域名
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/aixin"
ServerName www.aixin.com
ErrorLog "logs/www.aixin.com-error_log"
CustomLog "logs/www.aixin.com_log" common
</VirtualHost>
Listen 81 #一定要添加此行,启用81端口
<VirtualHost *:81>
DocumentRoot "/usr/local/apache/htdocs/tanchishe"
ServerName www.tanchishe.com
ErrorLog "logs/www.tanchishe.com-error_log"
CustomLog "logs/www.tanchishe.com_log" common
</VirtualHost>
#不同IP相同端口
[root@liu extra]# vim httpd-vhosts.conf
<VirtualHost 192.168.244.132:80>
DocumentRoot "/usr/local/apache/htdocs/aixin"
ServerName www.aixin.com
ErrorLog "logs/www.aixin.com-error_log"
CustomLog "logs/www.aixin.com_log" common
</VirtualHost>
<VirtualHost 192.168.244.144:80>
DocumentRoot "/usr/local/apache/htdocs/tanchishe"
ServerName www.tanchishe.com
ErrorLog "logs/www.tanchishe.com-error_log"
CustomLog "logs/www.tanchishe.com_log" common
</VirtualHost>
[root@liu conf]# ip addr add 192.168.244.144/24 dev eth0 #如果网卡只有一个IP则为当前网卡再添加一个IP
不同IP相同端口
#不同IP相同端口
[root@liu extra]# vim httpd-vhosts.conf
<VirtualHost 192.168.244.132:80>
DocumentRoot "/usr/local/apache/htdocs/aixin"
ServerName www.aixin.com
ErrorLog "logs/www.aixin.com-error_log"
CustomLog "logs/www.aixin.com_log" common
</VirtualHost>
<VirtualHost 192.168.244.144:80>
DocumentRoot "/usr/local/apache/htdocs/tanchishe"
ServerName www.tanchishe.com
ErrorLog "logs/www.tanchishe.com-error_log"
CustomLog "logs/www.tanchishe.com_log" common
</VirtualHost>
[root@liu conf]# ip addr add 192.168.244.144/24 dev eth0 #如果网卡只有一个IP则为当前网卡再添加一个IP
[root@liu conf]# apachectl restart #如果未生效重启一下apache
相同IP相同端口不同域名
[root@liu conf]# vim extra/httpd-vhosts.conf
<VirtualHost 192.168.244.132:80>
DocumentRoot "/usr/local/apache/htdocs/aixin"
ServerName www.aixin.com
ErrorLog "logs/www.aixin.com-error_log"
CustomLog "logs/www.aixin.com_log" common
</VirtualHost>
#Listen 81
<VirtualHost 192.168.244.132:80>
DocumentRoot "/usr/local/apache/htdocs/tanchishe"
ServerName www.tanchishe.com
ErrorLog "logs/www.tanchishe.com-error_log"
CustomLog "logs/www.tanchishe.com_log" common
</VirtualHost>
标签:httpd,常用,logs,虚拟主机,IP,www,conf,aixin,com 来源: https://www.cnblogs.com/Archer-x/p/16504217.html