要求
一个ip对应一个网。例如实现以下操作:
建立一个192.168.19.102的网站 ,文件放在/www/100,内容显示this is 192.168.19.102.
建立一个192.168.19.103的网站 ,文件放在/www/200,内容显示this is 192.168.19.103.
配置网络
首先给虚拟机配置三块网卡并设置好IP地址,默认网卡已经配置好
[root@server_1 ~]# nmcli connection modify eno33554960 ipv4.addresses 192.168.19.102/24 ipv4.gateway 192.168.19.1 ipv4.dns 8.8.8.8 ipv4.method manual connection.autoconnect yes
[root@server_1 ~]# nmcli connection modify eno50332184 ipv4.addresses 192.168.19.103/24 ipv4.gateway 192.168.19.1 ipv4.dns 8.8.8.8 ipv4.method manual connection.autoconnect yes
[root@server_1 ~]# nmcli connection up eno33554960
[root@server_1 ~]# nmcli connection up eno50332184
也可以去图形界面配置IP地址,这里我的三块网卡IP地址分别为
192.168.19.101
192.168.19.102
192.168.19.103
编辑配置文件
[root@server_1 ~]# mkdir -p /www/{100,200}
[root@server_1 ~]# echo this is 192.168.19.102 > /www/100/index.html
[root@server_1 ~]# echo this is 192.168.19.103 > /www/200/index.html
[root@server_1 ~]# vim /etc/httpd/conf.d/vhost.conf
<Directory /www>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.19.102>
DocumentRoot /www/100
ServerName 192.168.19.102
ServerAdmin root@localhost
</VirtualHost>
<VirtualHost 192.168.19.103>
DocumentRoot /www/200
ServerName 192.168.19.103
ServerAdmin root@localhost
</VirtualHost>
配置selinux
添加selinux上下文
[root@server_1 ~]# semanage fcontext -a -t httpd_sys_content_t /www"(/.*)?"
重新加载selinux上下文
[root@server_1 ~]# restorecon -vvFR /www
重启httpd服务
[root@server_1 ~]# systemctl restart httpd
客户端测试
[root@server_2 ~]# curl 192.168.19.102
this is 192.168.19.102
[root@server_2 ~]# curl 192.168.19.103
this is 192.168.19.103