2012-09-12 64 views
0

如下我已配置我的httpd-vhosts.conf文件:爲什麼我的虛擬主機沒有域名匹配?

<VirtualHost seg.localhost:81> 
    ServerAdmin [email protected] 
    DocumentRoot "D:\path\to\public_html" 
    ServerName http://seg.localhost 
    ServerAlias http://seg.localhost 
    ErrorLog "logs/seg.log" 
    CustomLog "logs/seg" common 
    <directory "D:\path\to\public_html"> 
     Options Indexes FollowSymLinks 
     AllowOverride all 
     Order Deny,Allow 
     Deny from all 
     Allow from all 
    </directory> 
</VirtualHost> 

但是,當我去http://localhost:81/在我的瀏覽器,它仍然擊中該文件夾。爲什麼忽略子域名?

回答

2

如果使用的是基於域名虛擬主機,最上面的虛擬主機(一個<VirtualHost>塊的第一個實例)被認爲是「默認」虛擬主機,這意味着如果一個請求是針對不主機發匹配任何給定的<VirtualHost>的,最高的一個被使用。

您可以通過添加,簡單地拒絕所有新的最頂端的虛擬主機解決這個問題:

<VirtualHost seg.localhost:81> 
    ServerName _default_ 
    DocumentRoot "D:\path\to\public_html" 
    <Directory "D:\path\to\public_html"> 
     Order Allow,Deny 
     Deny from all 
    </Directory> 
</VirtualHost> 

或將其重定向到seg.localhost,但是還是要處理它。