2013-04-02 239 views
2
NameVirtualHost指令警告

我经历了很多帖子阅读并2点在同一个IP地址配置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文件夹中的默认站点。

任何帮助真的很感激。

+0

所以,你得到一个警告......你看过吗?它说什么? –

+0

警告消息是标准的“虚拟主机127.0.0.1:80与虚拟主机127.0.0.1:80重叠,第一个优先。也许你需要虚拟主机指令” – user2236230

回答

4

你在你的httpd.conf中包含了你的vhosts.conf吗?

取消注释该行(即从一个“包含”)附近的httpd.conf的底部:

# 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

+0

我有,但是我需要添加任何东西到httpd- vhosts.conf文件?非常感谢。 – user2236230

+0

你的代码看起来很好,它看起来好像没有被使用。我看到你说你包含的代码来自httpd.conf - 我认为这是一个错字,但是这个代码实际上在httpd.conf中,而不是在httpd-vhosts.conf中? –

+0

代码仅在httpd.conf中 – user2236230

3

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

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

## must be first so the the wamp menu page loads 
<VirtualHost *:80> 
    ServerAdmin [email protected] 
    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>