2013-04-02 240 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>