本机IP eth0:192.168.244.150 eth0:0 192.168.244.158
1、基于相同IP不同port的VirtualHost
编辑新增配置项
vim /etc/
Listen 8080
Listen 8888
在最下列新增
<VirtualHost 192.168.244.150:8080>
DocumentRoot /var/www/html/website1
</VirtualHost>
<VirtualHost 192.168.244.150:8888>
DocumentRoot /var/www/html/website2
</VirtualHost>
创建目录:
mkdir /var/www/html/website1
mkdir /var/www/html/website2
echo website1 > /var/www/html/website1
echo website2 > /var/www/html/website2
重启服务: /etc/init.d/httpd restart
浏览器浏览测试
测试正常
2、基于相同port不同ip的VirtualHost
新增IP
ifconfig eth0:0 192.168.244.158
编辑新增配置项
vim /etc/
<VirtualHost 192.168.244.150:8888>
DocumentRoot /var/www/html/website1
</VirtualHost>
<VirtualHost 192.168.244.158:8888>
DocumentRoot /var/www/html/website2
</VirtualHost>
显示内容同上,因为DocumentRoot路径一样
/etc/init.d/httpd restart
同时打开两个浏览器进行测试
测试OK
3、基于相同IP相同port不同domain的VirtualHost
编辑新增配置项
vim /etc/
NameVirtualHost 192.168.244.150
<VirtualHost >
DocumentRoot /var/www/html/website1
ServerName
</VirtualHost>
<VirtualHost >
DocumentRoot /var/www/html/website2
ServerName
</VirtualHost>
重启httpd
/etc/init.d/httpd restart
修改本地hosts
192.168.244.150
192.168.244.150
进行基于域名测试
测试OK!!