Windows 主机文件中的通配符 [英] Wildcards in a Windows hosts file
问题描述
我想设置我的本地开发机器,以便将任何对 *.local
的请求重定向到 localhost
.这个想法是,当我开发多个站点时,我可以将名为 site1.local
、site2.local
等的虚拟主机添加到 Apache,并将它们全部解析为 localhost
,而 Apache 相应地为不同的站点提供服务.
I want to setup my local development machine so that any requests for *.local
are redirected to localhost
. The idea is that as I develop multiple sites, I can just add vhosts to Apache called site1.local
, site2.local
etc, and have them all resolve to localhost
, while Apache serves a different site accordingly.
我使用的是 Windows XP.
I am on Windows XP.
我尝试添加
127.0.0.1 *.local
到我的 c:\windows\system32\drivers\etc\hosts
文件,也试过:
to my c:\windows\system32\drivers\etc\hosts
file, also tried:
127.0.0.1 .local
这两个似乎都不起作用.
Neither of which seem to work.
我知道我可以在不同的端口号上设置它们,但这很痛苦,因为很难记住哪个端口是哪个.
I know I can set them up on different port numbers, but that is a pain since it is hard to remember which port is which.
我不想设置本地 DNS 服务器或任何困难,有什么建议吗?
I don't want to have to setup a local DNS server or anything hard, any suggestions?
推荐答案
Acrylic DNS Proxy(免费,开源)可以完成这项工作.它使用自己的主机文件创建代理 DNS 服务器(在您自己的计算机上).主机文件接受通配符.
Acrylic DNS Proxy (free, open source) does the job. It creates a proxy DNS server (on your own computer) with its own hosts file. The hosts file accepts wildcards.
从官网下载
http://mayakron.altervista.org/support/browse.php?path=亚克力&name=首页
要配置 Acrylic DNS 代理,请从上面的链接安装它,然后转到:
- 开始
- 程序
- 丙烯酸 DNS 代理
- 配置
- 编辑自定义主机文件 (AcrylicHosts.txt)
在文件末尾添加以下几行:
127.0.0.1 *.localhost
127.0.0.1 *.local
127.0.0.1 *.lc
重启 Acrylic DNS 代理服务:
- 开始
- 程序
- Acrilic DNS 代理
- 配置
- 重启 Acrylic 服务
您还需要在网络接口设置中调整 DNS 设置:
- 开始
- 控制面板
- 网络和互联网
- 网络连接
- 本地连接属性
- TCP/IPv4
设置使用以下 DNS 服务器地址":
Preferred DNS Server: 127.0.0.1
如果您随后将此答案与 jeremyasnyder 的答案结合起来(使用 VirtualDocumentRoot
),您就可以通过简单地创建目录来自动设置域/虚拟主机.
If you then combine this answer with jeremyasnyder's answer (using VirtualDocumentRoot
) you can then automatically setup domains/virtual hosts by simply creating a directory.
这篇关于Windows 主机文件中的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!