Search code examples
ubuntunginxserverdevops

extract word before first dot from url in nginx


I use nginx

Assume that url "hello.test.example.com", hello example of dynamically subdomain, how can i get the word before the first dot in nginx config ?? the result must be "hello" ?


Solution

  • For example:

    server {
        server_name ~^(?<subdomain>[^.]+)\.test\.example\.com$;
        ...
    }
    

    As of this configuration, the first part of subdomain name will be available as $subdomain variable value.