使用 dnsmasq 的 Nginx 正则表达式名称错误

Nginx regular expression name error with dnsmasq

我正在尝试将 Nginx 配置为在 .local 上使用通配符子域,其中子域也是文件夹的名称。例如,test-site.local:8080 的位置根应该是 /Users/ashley/www/sites/test-site/wwwdataanother.local:8080 应该是 /Users/ashley/www/sites/another/wwwdata.

我根据 Nginx docsnginx.conf 中设置了以下配置:

server {
    listen       8080;
    server_name  mbp.local ~^(?<domain>.+)\.local$;

    location / {
        root   /Users/ashley/www/sites/$domain/wwwroot;
        index  index.html;
    }
}

这不起作用(无法访问站点),如果我检查 error.log,我不会收到任何错误消息。但是,mbp.local 确实会产生错误:

2018/01/18 18:30:57 [error] 4968#0: *1 "/Users/ashley/www/sites//wwwroot/index.html" is not found (2: No such file or directory), client: 192.168.0.10, server: mbp.local, request: "GET / HTTP/1.1", host: "mbp.local:8080"

我做错了什么?

编辑:

我已经从 server_name 中删除了 mbp.local,因为我猜它在正则表达式上不匹配,因此没有 $domain 变量被传递到该位置。如果我现在尝试子域,则没有错误条目。基于浏览器中的站点无法访问错误和缺少条目,我只能假设 DNS 查找失败。我正在使用 dnsmasq 来解析 .local URL,它工作正常:

dig another.local @127.0.0.1
;; QUESTION SECTION:
;another.local.         IN  A
;; ANSWER SECTION:
another.local.      0   IN  A   127.0.0.1

我的网络设置中没有配置 DNS 服务器,添加 127.0.0.1 也没有用 - 只会导致所有 DNS 查找失败。关于为什么这不起作用的任何建议?

原来这既不是 Nginx(除了错误 mbp.local)也不是 dnsmasq 问题,而是 macOS 网络配置问题。

我需要在我的网络首选项中添加 .local 作为搜索域。