我想设置我的本地开发机器,以便任何对*的请求。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服务器,有什么建议吗?


当前回答

这可以使用Pi-Hole完成,只需编辑“/etc/hosts”并重新启动dns服务。

nano /etc/hosts
pihole restartdns

例子:

127.0.1.1       raspberrypi
192.168.1.1     w1.dev.net
192.168.1.2     w2.dev.net
192.168.1.3     w3.dev.net

其他回答

您可以使用动态DNS客户端,例如http://www.no-ip.com。然后,用外部DNS服务器CNAME *.mydomain.com改为mydomain.no-ip.com。

我用Python写了一个简单的dns代理。它将读取/etc/hosts中的通配符条目请看这里:http://code.google.com/p/marlon-tools/source/browse/tools/dnsproxy/dnsproxy.py

我在Linux和Mac OS X上测试过,但还没有在Windows上测试过。

我使用DNSChef来做这个。

https://thesprawl.org/projects/dnschef/

你必须下载应用程序,在Linux或Mac中,你需要python来运行它。Windows有自己的exe。

例如,您必须创建一个包含dns条目的ini文件

[A]
*.google.com=192.0.2.1
*.local=127.0.0.1
*.devServer1.com=192.0.2.3

然后,您必须以管理员权限启动dns应用程序

sudo python dnschef.py --file myfile.ini -q

或者在Windows中

runas dnschef.exe --file myfile.ini -q

最后,您需要设置为您的本地主机环境(网络,接口,DNS或类似或在linux /etc/resolv.conf)的唯一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";
}

配置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;您的项目路径