Nginx 比较数值大小

如何在 Nginx 中进行比较(大于):

if($a > $b){
    return 503
}

问题出现在:

... 条件中出现了意外的 ">"。

点赞
用户127660
用户127660

>< 符号中没有 <condition> 支持。

参见 http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if

但您可以使用 lua 来实现:

       location / {
        default_type text/plain;
        set $a 2;
        set $b 1;
        content_by_lua_block {
          if ngx.var.a > ngx.var.b then
            ngx.say("a > b")
          else
            ngx.say("a <= b")
          end
        }
    }

而且请确保在任何配置更改时重新启动 nginx。

2016-10-04 01:38:38