I want to use a variable in a regex. Like,
set $valid_host_regex ...
if ($host !~ ((^$)|($valid_host_regex))) {
return 404;
}
It seems it is not possible to use a variable name in regex string. How to use a variable in a regular expression in nginx?
So, I tried using complete regex as a variable
set $valid_host_regex ((^$)|(...))
if ($host !~ $valid_host_regex) {
return 404;
}
But this is also not working. Am I doing something wrong, or is it just not possible to use a variable in place of regex? I am not able to find any documentation or answer for this anywhere.
Thanks in advance