A
A
Azigar2019-09-11 13:17:03
Nginx
Azigar, 2019-09-11 13:17:03

How to add variable to regex in Nginx if()?

There is this part of the configuration:

set $domain        "mysite.com";
set $subdomain   "www";

if ($host ~* ^([a-z0-9-\.]+)\.$domain$) {
         set $subdomain $1;
}

If you log in from a subdomain, the $subdomain variable still has the value "www".
If you write mysite.com instead of $domain in the condition, then the $subdomain variable will have the value of the subdomain.
What am I not writing correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question