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


当前回答

你可以说服你的网络管理员为你设置一个域名(说'evilpuppetmaster.hell'),并在那里使用通配符,这样所有的东西(*.evilpuppetmaster.hell')都解析到你的IP

其他回答

@petah和丙烯酸DNS代理是最好的答案,最后他提到了使用Apache做多站点的能力,@jeremyasnyder在下面描述了一点…

... 然而,在我们的例子中,我们正在测试一个多租户托管系统,因此我们想要测试的大多数域都指向同一个虚拟主机,而其他一些域则指向其他地方。

所以在我们的例子中,你只需在ServerAlias指令中使用正则通配符,就像这样…

ServerAlias *.foo.local

我发现一个关于使用Windows主机文件的帖子也说“不允许通配符”。

在过去,我只是将额外的条目添加到hosts文件中,因为(如前所述),当您已经在编辑apache配置文件时,并没有那么多额外的工作。

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

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

我制作了这个简单的工具来代替主机。支持正则表达式。 https://github.com/stackia/DNSAgent

配置示例:

[
    {
        "Pattern": "^.*$",
        "NameServer": "8.8.8.8"
    },
    {
        "Pattern": "^(.*\\.googlevideo\\.com)|((.*\\.)?(youtube|ytimg)\\.com)$",
        "Address": "203.66.168.119"
    },
    {
        "Pattern": "^.*\\.cn$",
        "NameServer": "114.114.114.114"
    },
    {
        "Pattern": "baidu.com$",
        "Address": "127.0.0.1"
    }
]