为啥我设置的虚拟主机没效果啊(centos)
我在/etc/httpd/conf.d/下新建了一个 .conf的文件 内容如下
<VirtualHost *:80>
DocumentRoot /var/www/html2
ServerName www.myweb.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html3
ServerName www.myweb.cn
</VirtualHost>
www.myweb.com
www.myweb.cn
都做了映射的,咋两个都访问到的是html2中的内容了呢?
[解决办法]
#同一个IP 127.0.0.1的情况
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/html2
ServerName www.myweb.com
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/html3
ServerName www.myweb.cn
</VirtualHost>
#不同IP 127.0.0.1/2的时候
VirtualHost *:80
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/html2
ServerName www.myweb.com
</VirtualHost>
<VirtualHost 127.0.0.2:80>
DocumentRoot /var/www/html3
ServerName www.myweb.cn
</VirtualHost>