Hello!
2016-03-23 6:17 GMT-07:00 wangwei4514:
> 还有个问题,我在header_filter_by_lua中加入了如下代码,如果upstream返回502,我就想把502变为654
> {
> if ngx.status == 502 then
> ngx.status = 654
> ngx.log(ngx.ERR, "ngx.status : ", ngx.status)
> end
> }
>
> 当我执行ngx.log(ngx.ERR, "ngx.status : ", ngx.status)的时候,为什么还是返回的502,而不是654?
多谢报告!刚刚已经在 lua-nginx-module 的 git 仓库中修复了这个问题:
https://github.com/openresty/lua-nginx-module/commit/93321acd
值得一提的是,你这里使用下面的配置貌似更合适一些:
header_filter_by_lua_block {
if ngx.status == 502 then
return ngx.exit(654)
end
}
因为你原先的代码只修改了响应的状态码,而并没有影响到响应体。当然,如果响应体已经是你想要的了,那直接修改 ngx.status 也挺合适的。
Best regards,
-agentzh