Monday, April 3, 2017

nginx server_name regex

Leave a Comment

server_name in nginx does not match

I want to match with such FQDNs I came up with

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

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.

Is there any restriction im not aware of? Thank you.

3 Answers

Answers 1

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.

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 

Answers 2

I've never seen server_name configurations with double-quotes... but I'm not shure if that solves the problem.

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!

Answers 3

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. What is probably perceived as 2 separate entries, nginx interpolated as a single entry.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment