ngx.status变量未设置

时间:2013-10-22 19:44:36

标签: nginx lua

在我的nginx配置中,我设置了以下行以从lua提供回退错误页面:

error_page 502 @fallback;

location @fallback {
     content_by_lua_file 'fallback.lua';
}

location / {
    return 502;
}

然后在我的lua文件中,我在文件的顶部有以下内容:

ngx.log(ngx.ERR, "reported status is: " .. ngx.status)

我希望它是502但是报告ngx.status是0.

我试图通过编写

来解决这个问题
set $status 502

但是nginx抱怨$status是现有变量的副本,不会加载配置。

如何让lua从return指令中了解nginx状态?

2 个答案:

答案 0 :(得分:1)

看起来lua模块中的一个错误是阻止正确设置。

https://github.com/chaoslawful/lua-nginx-module/commit/82ba941d

答案 1 :(得分:1)

这是ngx_lua中的一个错误。 “return”指令的响应状态代码存储得比正常响应状态代码差,即r->err_status而不是r->headers_out.statusngx.status API只读取后者而不是前者。

此问题已在ngx_lua的主分支中修复为提交82ba941d:

https://github.com/chaoslawful/lua-nginx-module/commit/82ba941d

此修订将包含在下一版本的ngx_lua(0.9.1)和ngx_openresty(1.4.3.1)中。

感谢您的举报!

相关问题