In nginx I can use set
to define a variable, but is it possible to define a default?
e.g.
set $foo bar if $foo is not defined
In nginx I can use set
to define a variable, but is it possible to define a default?
e.g.
set $foo bar if $foo is not defined
or
This also works:
map $foo $foo {}
solves errornginx: [emerg] unknown "foo" variable
- just doesn't look right - but it works.Note:
map
must be in blockhttp {}
(nginx/conf.d
)map $foo $foo {}
gives mecycle while evaluating variable "foo"
error message in the nginx error log.Now,
does work and it's also semantically correct: if the regular expression matches anything then the result will be
$foo
if it doesn't then there are no characters to match so it becomesbar
. I do not think the configuration syntax for nginx makes it possible to distinguish between an empty string and an undefined variable. I believe you need openresty and a nil check for that.