思路:最好先做DNS,然后再做web服务器
主:
1、写配置文件、/etc/hosts文件等,创建目录,写index.html文件等
[root@localhost ~]# cd /etc/httpd/conf.d
[root@localhost conf.d]# cat vhost.conf
<directory /dadou> allowoverride none require all granted </directory>
<virtualhost 192.168.159.129:80> servername www.dadou.com documentroot /dadou </virtualhost>
<directory /xiaodou> allowoverride none require all granted </directory>
<virtualhost 192.168.159.129:80> servername www.xiaodou.com documentroot /xiaodou </virtualhost>
<directory /doudou> allowoverride none require all granted </directory>
<virtualhost 192.168.159.129:80> servername www.doudou.com documentroot /doudou </virtualhost>
2、开启防火墙,更改上下文标签
systemctl start firewalld
getenforce
ll -Z /dadou -d
ll -Z /var/www -d
chcon -t httpd_sys_content_t /dadou /xiaodou /doudou
ll -Z /dadou chcon -t httpd_sys_content_t /dadou/* /xiaodou/* /doudou/*
ll -Z /dadou
3、测试
netstat -lntup | grep http
curl http://www.dadou.com curl http://www.xiaodou.com curl http://www.doudou.com
4、做DNS配置
[root@localhost ~]# cat /etc/named.conf
options { listen-on port 53 { 192.168.159.129; }; directory "/var/named"; }; zone "." IN { type hint; file "named.ca"; };
zone "dadou.com" IN { type master; file "named.dadou"; };
zone "xiaodou.com" IN { type master; file "named.xiaodou"; };
zone "doudou.com" IN { type master; file "named.doudou"; };
[root@localhost ~]# cd /var/named [root@localhost named]# cat named.dadou $TTL 1d @ IN SOA @ admin.dadou.com. (2024070601 1 1 1 1)
IN NS ns.dadou.com.
ns IN A 192.168.159.129 www IN A 192.168.159.129
其余几个一样
从
1、写配置文件等,创建目录,写index.html文件等
[root@localhost ~]# cat /etc/httpd/conf.d/vhost.conf
<directory /3031> allowoverride none require all granted </directory>
listen 3031 <virtualhost 192.168.159.131:3031> servername 192.168.159.131 documentroot /3031 </virtualhost>
<directory /3032> allowoverride none require all granted </directory>
listen 3032 <virtualhost 192.168.159.131:3032> servername 192.168.159.131 documentroot /3032 </virtualhost>
<directory /3033> allowoverride none require all granted </directory>
listen 3033 <virtualhost 192.168.159.131:3033> servername 192.168.159.131 documentroot /3033 </virtualhost>
2、开启防火墙,改上下文标签,添加端口号
ll -Z /3031 -d ll -Z /var/www -d
chcon -t httpd_sys_content_t /303{1..3}/*
semanage port -l | grep http
semanage port -a -t http_port_t -p tcp 3031
semanage port -a -t http_port_t -p tcp 3032
semanage port -a -t http_port_t -p tcp 3033
semanage port -l | grep http
firewall-cmd --reload netstat -lntup | grep http
firewall-cmd --permanent --add-port=3031/tcp
firewall-cmd --permanent --add-port=3032/tcp
firewall-cmd --permanent --add-port=3033/tcp
firewall-cmd --reload
netstat -lntup | grep http
3、DNS,改一下IP等信息
4、测试
curl http://192.168.159.131:3032 curl http://192.168.159.131:3031 curl http://www.dadou.com curl http://www.xiaodou.com curl http://www.doudou.com