【发布时间】:2013-12-07 21:32:20
【问题描述】:
我最近想将所有子域指向一个测试域,比如说 example.com 到 localhost。有没有办法将 *.example.com 上的所有请求都指向 127.0.0.1
【问题讨论】:
标签: hosts
我最近想将所有子域指向一个测试域,比如说 example.com 到 localhost。有没有办法将 *.example.com 上的所有请求都指向 127.0.0.1
【问题讨论】:
标签: hosts
/etc/hosts 文件恰好不支持通配符条目。
您必须使用其他服务,例如 dnsmasq。要在 dnsmasq 中启用它,只需编辑 dnsmasq.conf 并添加以下行:
address=/example.com/127.0.0.1
【讨论】:
dnsmasq 设置参见 this one。
这里是那些试图实现原始目标的配置(通配符都指向同一个代码库——什么都不安装,开发环境,即 XAMPP)
文件:/etc/hosts(非 Windows)
127.0.0.1 example.local
文件:/XAMPP/etc/httpd.conf
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
文件:XAMPP/etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin admin@example.local
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
将文件保存为whatever.pac,然后在浏览器的网络中加载该文件>代理>自动配置设置(如果您更改此设置,请重新加载)
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*example.local")) {
return "PROXY example.local";
}
return "DIRECT";
}
【讨论】:
使用 dnsmasq
假设您使用的是基于 Debian 的 dist(ubuntu, mint..),请检查它是否安装了
(sudo) systemctl status dnsmasq
如果它刚刚被禁用,请使用
(sudo) systemctl start dnsmasq
如果一定要安装,写
(sudo) apt-get install dnsmasq
定义域以解析编辑/etc/dnsmasq.conf 像这样。
address=/example.com/127.0.0.1
解决 *.example.com
!您必须重新加载 dnsmasq 才能使更改生效!
systemctl reload dnsmasq
【讨论】: