简体   繁体   English

nginx server_name正则表达式

[英]nginx server_name regex

server_name in nginx does not match nginx中的server_name不匹配

I want to match with such FQDNs I came up with 我希望与我提出的这样的FQDN相匹配

server_name "~^(www.)?ucwebapi-uccore(\d{0,3})-(\d{0,3})\.testme\.net";

To Match 匹配

ucwebapi.testme.net
ucwebapi-uccore.testme.net
ucwebapi-uccore1-0.testme.net
ucwebapi-uccore999-999.testme.net

Validated with https://regex101.com/r/tAwEp9/2 通过https://regex101.com/r/tAwEp9/2验证

Tested with 经过测试

server_name "~^(www.)?ucwebapi-uccore(\d{0,3})-(\d{0,3})\.testme\.net ucwebapi1.testme.net";

to see if ucwebapi1.testme.de server is reachable at all. 看看ucwebapi1.testme.de服务器是否可以访问。

Is there any restriction im not aware of? 我不知道有什么限制吗? Thank you. 谢谢。

Try this: 试试这个:

server_name "~^(www.)?ucwebapi(-uccore)?(\d{1,3}-\d{1,3})?\.testme\.net";

It looks like there are some missing characters between your regex101 page and what ended up in your config. 看起来你的regex101页面和你的配置中出现的内容之间有一些缺失的字符。

I've also tuned it a bit so that it will NOT match: 我也调了一下,所以它不匹配:

ucwebapi-uccore999.testme.net
ucwebapi-uccore-.testme.net
ucwebapi-uccore-999.testme.net

I've never seen server_name configurations with double-quotes... but I'm not shure if that solves the problem. 我从来没有见过带双引号的server_name配置......但是如果能解决问题的话,我不会感到害羞。

Some example configurations here . 这里有一些示例配置。

Edit: Do you have a default virtual server like this: 编辑:你有这样的默认虚拟服务器:

server {
    listen 80;
    server_name _;
    return 404; # default
}

# now add your specific server
server {
    listen 80;
    server_name "~^(www.)?ucwebapi-uccore(\d{0,3})-(\d{0,3})\.testme\.net ucwebapi1.testme.net";
    ...
}

Specific configurations will only work if you have a default configured. 只有配置了默认配置,才能使用特定配置。

@abcdn : your absolutely right, i didn't know that! @abcdn :你绝对正确,我不知道!

Try: 尝试:

server_name "~^(www.)?ucwebapi-uccore(\d{0,3})-(\d{0,3})\.testme\.net" ucwebapi1.testme.net;

Your server_name quotes encompassed the entire line. 您的server_name引号包含整行。 What is probably perceived as 2 separate entries, nginx interpolated as a single entry. 什么可能被视为2个单独的条目,nginx插值为单个条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM