I have two server sections for nginx in different files.
The first one:
server {
server_name _;
...
}
The second one:
server {
server_name ~someRegex;
...
}
I have some constraints - I can't change the first server section (i.e. I can't edit first file)
Documentation says the following about server names priority:
- exact name
- longest wildcard name starting with an asterisk, e.g. “*.example.org”
- longest wildcard name ending with an asterisk, e.g. “mail.*”
- first matching regular expression (in order of appearance in a configuration file)
As I understand server_name _
is used as catch-all server.
So when I have request from host matched someRegex request is handled by first server section. Is there a way to handle these request by second server section?
Not quite.
_
simply renders the server_name
invalid. See this document.
What makes a server
block the default is either being defined first for a given port or being defined with the listen ... default_server
modifier. See this document.
So your configuration will work as you expect, assuming that your regex is valid and that the second server block has indeed been installed by nginx
. Check your error log after reloading nginx
and/or test the configuration using
nginx -t