D
D
Dmitry2020-10-07 12:59:07
Nginx
Dmitry, 2020-10-07 12:59:07

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;
    }
}

Tell me, I have reserved and necessary subdomains like stage1.example.com and others. They have their own separate nginx configuration files and their own separate directories.
Is it possible to somehow add these domains to the exceptions? so that this rule does not apply to them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-10-07
@liggth

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:
  1. exact name
  2. the longest name with a mask at the beginning, for example “*.example.com”
  3. the longest name with a mask at the end, for example “mail.*”
  4. 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 question

Ask a Question

731 491 924 answers to any question