Answer the question
In order to leave comments, you need to log in
Creating dynamic nginx subdomains?
I implement the creation of dynamic subdomains. Used by nginx.
The code
server {
server_name ~^(?<dynamic>[a-z0-9\-]+)\.example.com$;
location / {
proxy_pass 127.0.0.1:80/sites/$dynamic$uri$is_args$args;
}
}
Answer the question
In order to leave comments, you need to log in
Just create separate server blocks for them
https://nginx.org/ru/docs/http/ngx_http_core_modul...
When searching for a virtual server by name, if the name matches more than one of the specified options, for example, both the name with a mask and the regular expression match, the first matching option will be selected in the following order of precedence:
- exact name
- the longest name with a mask at the beginning, for example “*.example.com”
- the longest name with a mask at the end, for example “mail.*”
- first matching regular expression (in the order in the config file)
server {
server_name ~^(?<dynamic>[a-z0-9\-]+)\.example.com$;
...
}
server {
server_name stage1.example.com;
....
}
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question