本机IP  eth0:192.168.244.150 eth0:0 192.168.244.158

1、基于相同IP不同port的VirtualHost

编辑httpd.conf新增配置项

vim /etc/httpd/conf/httpd.conf

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

浏览器浏览测试

112425613.jpg

测试正常

2、基于相同port不同ip的VirtualHost

新增IP

ifconfig eth0:0 192.168.244.158

编辑httpd.conf新增配置项

vim /etc/httpd/conf/httpd.conf

<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

同时打开两个浏览器进行测试

113036821.jpg

测试OK

3、基于相同IP相同port不同domain的VirtualHost

编辑httpd.conf新增配置项

vim /etc/httpd/conf/httpd.conf

NameVirtualHost 192.168.244.150
<VirtualHost www.lansgg1.com>
DocumentRoot /var/www/html/website1
ServerName      www.lansgg1.com
</VirtualHost>
<VirtualHost www.lansgg2.com>
DocumentRoot /var/www/html/website2
ServerName      www.lansgg2.com
</VirtualHost>

重启httpd

/etc/init.d/httpd restart

修改本地hosts

192.168.244.150 www.lansgg1.com
192.168.244.150 www.lansgg2.com

进行基于域名测试

114353163.jpg

测试OK!!