[root@Centos7-1 ~]# mkdir /var/www/ip1 /var/www/ip2
[root@Centos7-1 ~]# echo "this is 192.168.10.1's web.">/var/www/ip1/index.html
[root@Centos7-1 ~]# echo "this is 192.168.10.2's web.">/var/www/ip2/index.html
③ 添加/etc/httpd/conf.d/vhost.conf文件。该文件的内容如下:
[root@Centos7 ~]# vim /etc/httpd/conf.d/vhost.conf
<Virtualhost 192.168.10.1>
DocumentRoot /var/www/ip1
</Virtualhost>
<Virtualhost 192.168.10.2>
DocumentRoot /var/www/ip2
</Virtualhost>
④ SELnux设置为允许,让防火墙放行httpd服务,重启httpd服务。
[root@Centos7 ~]# setenforce 0
[root@Centos7 ~]# getenforce
Permissive
[root@Centos7 ~]# firewall-cmd --permanent --add-service=http
success
[root@Centos7 ~]# firewall-cmd --reload
success
[root@Centos7 ~]# systemctl restart httpd
⑤ 在客户端浏览器中可以看到http://192.168.10.1和http://192.168.10.2两个网站的浏览效果如图2所示。
图2 测试时出现默认页面
奇怪!为什么看到了httpd服务程序的默认首页面?
<Directory "/var/www/ip1">
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www/ip2">
AllowOverride None
Require all granted
</Directory>
[root@Centos7-1 ~]# mkdir /var/www/www1 /var/www/www2
[root@Centos7-1 ~]# echo "www1.devil.com's web.">/var/www/www1/index.html
[root@Centos7-1 ~]# echo "www2.devil.com's web.">/var/www/www2/index.html
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
③ 修改/etc/httpd/conf.d/vhost.conf文件。该文件的内容如下(原来内容清空):
<Virtualhost 192.168.10.1>
DocumentRoot /var/www/www1
ServerName www1.devil.com
</Virtualhost>
<Virtualhost 192.168.10.1>
DocumentRoot /var/www/www2
ServerName www2.devil.com
</Virtualhost>
[root@Centos7-1 devil]# vim /var/named/devil.com.zone
$TTL 1D
@ IN SOA dns.devil.com. mail.devil.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns.devil.com.
@ IN MX 10 mail.devil.com.
dns IN A 192.168.10.1
www1 IN A 192.168.10.1
www2 IN A 192.168.10.1
[root@Centos7-1 ~]# mkdir /var/www/8088 /var/www/80
[root@Centos7-1 ~]# echo "8088 port‘s web.">/var/www/8088/index.html
[root@Centos7-1 ~]# echo "80 port‘s web.">/var/www/80/index.html
② 修改/etc/httpd/conf/httpd.conf文件。该文件的修改内容如下:
Listen 8088
Listen 80
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
③ 修改/etc/httpd/conf.d/vhost.conf文件。该文件的内容如下(原来内容清空):
<Virtualhost 192.168.10.1:8088>
DocumentRoot /var/www/8088
</Virtualhost>
<Virtualhost 192.168.10.1:80>
DocumentRoot /var/www/80
</Virtualhost>
④ 关闭防火墙和允许SELinux,重启httpd服务。然后在客户端Client1上测试。测试结果大失所望!如图3所示。
图3 访问192.168.10.1: 8088报错
⑤ 处理故障。这是因为firewall防火墙检测到8088和80端口原本不属于Apache服务应该需要的资源,但现在却以httpd服务程序的名义监听使用了,所以防火墙会拒绝使用Apache服务使用这两个端口。
[root@Centos7-1 ~]# firewall-cmd --list-all
public (active) …………<略>
services: ssh dhcpv6-client samba dns http
ports:
…………<略>
[root@Centos7-1 ~]#firewall-cmd --zone=public --add-port=8088/tcp
success
[root@Centos7-1 ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
[root@Centos7-1 ~]# firewall-cmd --permanent --zone=public --add-port=8088/tcp
[root@Centos7-1 ~]# firewall-cmd --reload
[root@Centos7-1 ~]# firewall-cmd --list-all
public (active)
…………<略>
services: ssh dhcpv6-client samba dns http
ports: 80/tcp 8088/tcp
…………<略>
⑥ 再次在Client1上测试,结果如图4所示。
图4 不同端口虚拟机的测试结果
技巧:依次单击“Applications"→“Sundry”→“Firewall”,打开防火墙配置窗口,可以详尽地配置防火墙,包括配置 public 区域的port(端口)等,读者不妨多操作试试,定会有惊喜。
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务