我已经阅读了许多帖子,并在同一IP地址上为2个站点配置了WAMP,如下所示(httpd.conf提取):

#Tell Apache to identify which site by name
NameVirtualHost *:80

#Tell Apache to serve the default WAMP server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>

#Tell Apache configuration for 1 site
<VirtualHost 127.0.0.1>
ServerName client1.localhost
DocumentRoot "C:/wamp/www_client1"
<Directory "C:/wamp/www_client1">
allow from all
order allow,deny
AllowOverride all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>

#Tell Apache configuration for 2 site
<VirtualHost 127.0.0.1>
ServerName client2.localhost
DocumentRoot "C:/wamp/www_client2"
<Directory "C:/wamp/www_client2">
allow from all
order allow,deny
AllowOverride all
</Directory>


我还更改了Windows主机文件以添加127.0.0.1 client1.localhost等,但是,当我重新启动WAMP服务时,//client1.localhost和//client2.localhost转到c:\ wamp \ www中的默认站点夹。

任何帮助真的很感激。

最佳答案

您是否已将vhosts.conf包含在httpd.conf中?

取消注释httpd.conf底部附近的这一行(以“ include”开头的行)的注释:

# Virtual hosts - leave this commented
Include conf/extra/httpd-vhosts.conf


编辑:
看来问题在于NameVirtualHostVirtualHost必须匹配,所以不能有NameVirtualHost *:80VirtualHost 127.0.0.1。而是使用NameVirtualHost *:80VirtualHost *:80NameVirtualHost 127.0.0.1:80VirtualHost 127.0.0.1

如果它们不匹配,您将看到注释中提到的行为,其中不匹配的虚拟主机将受到攻击,或者如果它们都相同,则第一个启动(您的默认本地主机)击中。

有关更多信息,请参见此帖子:Wamp Server: Multiple Virtual Hosts are not working on Windows

10-08 06:34