How to get subdomain of URL in NGINX How to get subdomain of URL in NGINX nginx nginx

How to get subdomain of URL in NGINX


The domain name part of the URL is not tested by the location directive. You will need to use a named capture in the server_name directive. See this document for details.

For example:

server {    server_name ~^(?<name>\w+)\.example\.com$;    location /admin {        return 301 $scheme://$name.myurl.com/;    }}