Localhost的NameVirtualHost指令警告

时间:2013-04-02 13:17:59

标签: apache wamp

我已阅读了很多帖子,并为同一IP地址的2个站点配置了WAMP,如下所示(httpd.conf extract):

#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文件夹。

任何帮助都非常感激。

2 个答案:

答案 0 :(得分:4)

您是否已将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

答案 1 :(得分: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>