在 nginx 配置服务器名称中使用通配符

Ome*_*ega 1 configuration nginx server-name

我想在 nginx 配置服务器名称中使用通配符

例子)

server_name m.*.domain.com;
Run Code Online (Sandbox Code Playgroud)

但它表明

nginx: [emerg] invalid server name or wildcard "m.*.domain.com" on 0.0.0.0:80
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)

有可能解决这个问题的方法吗?

fla*_*man 5

对于未来的问题,您还可以查看这里:

http://nginx.org/en/docs/http/server_names.html

nginx 中通配符的接纳方式为.example.com 或 www.example。,但不在 www.*.example.com 或 www.*example.com 中,这些是无效的。

您可以做的是使用如下正则表达式:

server_name ~^www\..+\.example\.org$
Run Code Online (Sandbox Code Playgroud)

或者

server_name ~^w.*\.example\.org$
Run Code Online (Sandbox Code Playgroud)

在你的情况下会是这样的:

server_name ~^m.*\.domain\.com$
Run Code Online (Sandbox Code Playgroud)

请记住,正则表达式与 Perl(编程语言)接受的正则表达式相同。