我想设置我的本地开发机器,以便任何对*的请求。Local被重定向到localhost。这个想法是,当我开发多个站点时,我只需向Apache添加名为site1的vhosts。地方,site2。让它们都解析到localhost,而Apache则相应地服务于不同的站点。
我用的是Windows XP。
我试着加上
127.0.0.1 *.local
到我的c:\windows\system32\drivers\etc\hosts文件,也试过:
127.0.0.1 .local
这两种方法似乎都不管用。
我知道我可以在不同的端口号上设置它们,但这是一种痛苦,因为很难记住哪个端口是哪个端口。
我不想设置本地DNS服务器,有什么建议吗?
下面是那些试图实现目标的人的总配置(开发环境中的通配符,例如XAMPP——这个例子假设所有站点都指向相同的代码库)
Hosts文件(添加一个条目)
文件:% SystemRoot % \ system32 etc, etc drivers \ \ hosts
127.0.0.1 example.local
Httpd.conf配置(启用vhosts)
文件:etc, etc XAMPP \ \ httpd上。
# Virtual hosts
Include etc\extra\httpd-vhosts.conf
httpd-vhosts.conf配置
额外文件:XAMPP \ etc \ \ 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
创建pac文件:
保存成任何形式。Pac你想在任何地方,然后加载文件在浏览器的网络>代理>auto_configuration设置(重新加载,如果你改变这个)
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*example.local")) {
return "PROXY example.local";
}
return "DIRECT";
}
我找不到书面禁止,但按照惯例,Windows hosts文件紧跟UNIX hosts文件,不能在该文件中放入通配符主机名引用。
如果你阅读手册页,它说:
DESCRIPTION
The hosts file contains information regarding the known hosts on the net-
work. For each host a single line should be present with the following
information:
Internet address
Official host name
Aliases
尽管它说,
Host names may contain any printable character other than a field delim-
iter, newline, or comment character.
从实践层面来看,这是不正确的。
基本上,查看/etc/hosts文件的代码不支持通配符条目。
解决方法是提前创建所有的条目,可能使用一个脚本来一次性放置几百个条目。
丙烯酸DNS代理(免费,开源)的工作。它用自己的hosts文件创建一个代理DNS服务器(在您自己的计算机上)。hosts文件接受通配符。
官方网站下载
http://mayakron.altervista.org/support/browse.php?path=Acrylic&name=Home
配置亚克力DNS代理
要配置丙烯酸DNS代理,从上面的链接安装它,然后转到:
开始
项目
丙烯酸DNS代理
配置
编辑定制主机文件(AcrylicHosts.txt)
在文件末尾添加如下代码:
127.0.0.1 *.localhost
127.0.0.1 *.local
127.0.0.1 *.lc
重新启动丙烯酸DNS代理服务:
开始
项目
Acrilic DNS代理
配置
重启亚克力服务
您还需要在网络接口设置中调整DNS设置:
开始
控制面板
网络与互联网
网络连接
本地连接属性
TCP / IPv4
设置“使用以下DNS服务器地址”:
Preferred DNS Server: 127.0.0.1
如果你把这个答案和jeremyasnyder的答案结合起来(使用VirtualDocumentRoot),你就可以通过简单地创建一个目录来自动设置域/虚拟主机。