请参见下面的代码:
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
最简单的解决方法是在nginx配置中打开rewrite_by_lua_no_postpone
。
我认为有[[some原因(也许是性能?),为什么默认情况下未启用它。