2

我已经阅读了许多帖子,并为同一 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 中的默认站点文件夹。

任何帮助都非常感谢。

4

2 回答 2

4

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

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

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

编辑: 看起来问题是NameVirtualHostandVirtualHost必须匹配,所以你不能有NameVirtualHost *:80and VirtualHost 127.0.0.1。相反,使用NameVirtualHost *:80andVirtualHost *:80NameVirtualHost 127.0.0.1:80and VirtualHost 127.0.0.1

如果它们不匹配,您将看到评论中提到的行为,其中与其他虚拟主机不匹配的虚拟主机将被命中,或者如果它们都相同,则第一个(您的默认本地主机)将获得打。

有关更多信息,请参阅此帖子:Wamp 服务器:多个虚拟主机无法在 Windows 上运行

于 2013-04-02T15:50:07.650 回答
3

试试这个配置,它只是你的一些小修改

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

## must be first so the the wamp menu page loads
<VirtualHost *:80>
    ServerAdmin webmaster@homemail.net
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "C:/wamp/www">
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

#Tell Apache configuration for 1 site
<VirtualHost *:80>
   ServerName client1.localhost
   DocumentRoot "C:/wamp/www_client1"
   <Directory "C:/wamp/www_client1">
      AllowOverride All
      order Allow,Deny
      Allow from all
   </Directory>
   DirectoryIndex index.html index.php
</VirtualHost>

#Tell Apache configuration for 2 site
<VirtualHost *:80>
    ServerName client2.localhost
    DocumentRoot "C:/wamp/www_client2"
    <Directory "C:/wamp/www_client2">
        AllowOverride All
        order Allow,Deny        
        Allow from all
</Directory>
于 2013-04-27T01:17:00.740 回答