我设置了2个虚拟主机,共享同一个IP地址:
<VirtualHost *>
DocumentRoot "/var/www/vhosts/website1.com/httpdocs"
ServerName www.website1.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "/var/www/vhosts/website2.com/httpdocs"
ServerName www.website2.com
</VirtualHost>
如果我输入 www.website2.com,则显示的文件始终来自 www.website1.com
每次更改后我都会正确地重新启动 Apache。
我不明白为什么会发生这种事。
答案1
我找到了解决方案:
指令VirtualHost
应该与NameVirtualHost
值相匹配。
就我而言,我只是设置了一个简单的http
,因此*:80
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www/vhosts/website1.com/httpdocs"
ServerName www.website1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/vhosts/website2.com/httpdocs"
ServerName www.website2.com
</VirtualHost>