var在rewrite_by_lua_block之后不起作用

问题描述 投票:0回答:1

请参见下面的代码:

set $RUN_VERSION 'current';
rewrite_by_lua_block {
    ....
    ngx.var.RUN_VERSION = 'new'
}
echo $RUN_VERSION;
--------------------
visit the server: new
It seems work.

================================================ ========

set $RUN_VERSION 'current';
rewrite_by_lua_block {
    ....
    ngx.var.RUN_VERSION = 'new'
}
echo $RUN_VERSION;

if ($RUN_VERSION = "new"){
    echo "11111";
}
if ($RUN_VERSION = "current"){
    echo "22222";
}
--------------------
visit the server: 22222

第二种情况下的问题:1.回显$ RUN_VERSION;什么也没显示。2.应该显示11111

if-statement nginx lua set
1个回答
0
投票

最简单的解决方法是在nginx配置中打开rewrite_by_lua_no_postpone

我认为有[[some原因(也许是性能?),为什么默认情况下未启用它。

© www.soinside.com 2019 - 2024. All rights reserved.