2013-12-07 20 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

相关问题