0

我们需要请求主机的域部分。

Fe:如果www1.domX.here是请求的主机,我们需要domX.here变量。

不工作:

map $http_host $this_dom {
        default $http_host;
        ~^www1\.(?<this_dom>)$ $this_dom;
}

server {
        server_name 
                www1.dom1.here
                www1.dom2.here
                www1.dom3.here
                www1.dom4.here
                www1.dom5.here;

        location /somestuff {
                # local content delivery
                root /shared/somestuff;
        }

        location / {
                return 301 https://www.$this_dom$request_uri;
        }
}

此示例导致一个空域。

目前以这种方式解决了它:

if ($host ~* ^www1\.(.*)$) {
        set $this_dom $1;
}
4

1 回答 1

0

感谢Ivan Shatsky,解决方案是:

map $host $this_domain {
        default $host;
        ~www1\.(.*)$ $1;
}
于 2021-10-17T18:04:09.563 回答