如果条件在nginx配置文件app.conf中的if条件内,则无法使用

时间:2016-07-05 14:38:44

标签: nginx

我正在检查一些IF条件(在服务器指令内),如果它被传递,则检查其他IF条件,如果它也被传递,则返回一些测试。我的代码如下

if ($a != "Tree") {
if ($a != "Plant") { return 403 "It is not tree or plant"; 
 }
 }

当我使用这段代码时,我收到第二个IF错误,因为这里不允许使用“if”指令。

1 个答案:

答案 0 :(得分:2)

如果您需要检查多个条件,可以使用this

在你的情况下,它将是:

if ($a != "Tree") { 
  set $test  no-tree; 
} 

if ($a != "Plant") { 
  set $test  "${test}+no-plant"; 
} 

if ($test = no-tree+no-plant) { 
    return 403 "It is not tree or plant";
} 

但除非真的有必要,否则我不建议使用它。