2013-12-07 15 views

回答

70

發生這種情況/etc/hosts文件不支持通配符條目。

您必須使用其他服務,如dnsmasq。要啓用它的dnsmasq,只需編輯dnsmasq.conf並添加以下行:

address=/example.com/127.0.0.1 
+4

爲通配符項 - 地址=/example.com /127.0.0.1 – Vivek

+0

@Vivek它不是必需的 –

+4

對於Ubuntu的''dnsmasq'設置看看[這一個](http://askubuntu.com/questions/150135/how-to-block-specific-domains-in-hosts-file/150180#150180)。 – lemonsqueeze

7

這裏是爲那些努力實現原來的目標配置(通配符都指向同一個代碼庫 - 安裝什麼都沒有,開發環境即XAMPP)

主機文件(添加條目)

文件中:/ etc /主機(非視窗)

127.0.0.1 example.local 

httpd.conf配置(啓用虛擬主機)

文件:/XAMPP/etc/httpd.conf

# Virtual hosts 
Include etc/extra/httpd-vhosts.conf 

的httpd-vhosts.conf配置

文件:XAMPP的/ etc /額外/ httpd的-vhosts.conf

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "/path_to_XAMPP/htdocs" 
    ServerName example.local 
    ServerAlias *.example.local 
# SetEnv APP_ENVIRONMENT development 
# ErrorLog "logs/example.local-error_log" 
# CustomLog "logs/example.local-access_log" common 
</VirtualHost> 

重啓Apache

創建PAC文件:

另存爲whatever.pac無論你想,然後加載在瀏覽器的網絡>代理> auto_configuration設置的文件(重新加載,如果你改變這一點)

function FindProxyForURL(url, host) { 
    if (shExpMatch(host, "*example.local")) { 
    return "PROXY example.local"; 
    } 
    return "DIRECT"; 
} 
+0

不適用於Windows上的主機文件。它只會接受www.example.com –

+1

這可以在windows上使用firefox中的pac文件進行工作。我已經在多臺Windows機器上測試過了。 hosts文件只需要一個條目,pac文件處理子域。 –

+0

根據我的理解,原來的問題不是關於apache,而是關於網絡層面,所以我認爲你的回答錯過了點:/ – enTropy

相關問題