Windows 主机文件中的通配符 [英] Wildcards in a Windows hosts file

查看:69
本文介绍了Windows 主机文件中的通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置我的本地开发机器,以便将任何对 *.local 的请求重定向到 localhost.这个想法是,当我开发多个站点时,我可以将名为 site1.localsite2.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 代理,请从上面的链接安装它,然后转到:

  1. 开始
  2. 程序
  3. 丙烯酸 DNS 代理
  4. 配置
  5. 编辑自定义主机文件 (AcrylicHosts.txt)

在文件末尾添加以下几行:

127.0.0.1   *.localhost
127.0.0.1   *.local
127.0.0.1   *.lc

重启 Acrylic DNS 代理服务:

  1. 开始
  2. 程序
  3. Acrilic DNS 代理
  4. 配置
  5. 重启 Acrylic 服务

您还需要在网络接口设置中调整 DNS 设置:

  1. 开始
  2. 控制面板
  3. 网络和互联网
  4. 网络连接
  5. 本地连接属性
  6. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆