使用set在Nginx中设置默认变量


10

在nginx中,我可以set用来定义变量,但是可以定义默认值吗?

例如

set $foo bar if $foo is not defined

2
你想达到什么目的?
迈克尔·汉普顿

Answers:



0

这也适用:

map $foo $foo {
    default '';
}
map $foo $bar {
    default '';
    'bar' 'bar';
    'foo' $foo;   <----- nginx: [emerg] unknown "foo" variable
}

map $foo $foo {}解决错误nginx: [emerg] unknown "foo" variable -看起来不正确-但可以。

注意:map必须在方块http {}nginx/conf.d)中

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.