我想设置我的本地开发机器,以便任何对*的请求。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服务器,有什么建议吗?
我们在本地DNS服务器中使用通配符DNS:添加一个A记录,比如*。Local -> 127.0.0.1
我认为你的网络设置需要在网络上机器的域名后缀搜索列表中有所选择的域名后缀,所以你可能想用你公司的内部域名(例如.int)取代.local,然后添加一个子域名,如.localhost.int,以明确它的用途。
因此,*.localhost.int将为网络上的每个人解析为127.0.0.1,如果端点挂起子域(例如site1.localhost.int, site2.localhost.int),则所有开发人员的配置文件设置将“正常工作”。
dnsmasq看起来也不错,但我还没有尝试过:
http://ihaveabackup.net/2012/06/28/using-wildcards-in-the-hosts-file/
我找不到书面禁止,但按照惯例,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文件的代码不支持通配符条目。
解决方法是提前创建所有的条目,可能使用一个脚本来一次性放置几百个条目。
您可以使用echoipdns (https://github.com/zapty/echoipdns)。
通过运行echoipdns local,所有对.local子域的请求都被重定向到127.0.0.1,因此任何具有xyz. local子域的域。本地etc将解析为127.0.0.1。您可以使用任何其他后缀,也只是用您想要的名称替换local。
Echoipdns甚至更强大,当你想使用你的url从其他机器在网络中,你仍然可以使用它零配置。
例如,如果你的机器ip地址是192.168.1.100,你现在可以使用一个域名xyz.192-168-1-100。本地的,将始终解析为192.168.1.100。这个魔术是由echoipdns通过查看域名的第二部分中的ip地址,并在DNS查询中返回相同的ip地址来完成的。您必须在要访问远程系统的机器上运行echoipdns。
echoipdns也可以设置为一个独立的DNS代理,因此,只要指向这个DNS,您现在就可以使用所有上述优点,而无需每次都运行一个特殊的命令,甚至可以从移动设备使用它。
因此,从本质上讲,这简化了本地和团队环境中基于通配符域的DNS开发。
echoipdns适用于Mac、Linux和Windows。
注:我是echoipdns的作者。
配置nginx配置自动子域与丙烯酸DNS代理
你的nginx sites文件夹的Auto.conf文件
server {
listen 80;
server_name ~^(?<branch>.*)\.example\.com;
root /var/www/html/$branch/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_log /var/log/nginx/$branch.error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
添加到Acrylic hosts文件127.0.0.1 example.com *.example.com并重新启动Acrylic服务。
$branch -你的子域名。
设置代替根/var/www/html/$branch/public;您的项目路径
下面是那些试图实现目标的人的总配置(开发环境中的通配符,例如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";
}