context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*
Read and write the current request's response status. This should be called before sending out the response headers.
ngx.status = ngx.HTTP_CREATED status = ngx.status
Setting ngx.status after the response header is sent out has no effect but leaving an error message in your nginx's error log file:
ngx.status
attempt to set ngx.status after sending out response headers
大家好,我想利用状态码的值来做一些响应,但是ngx.var.status无法得到正确的值,全是0.请教下大家怎么回事啊? --
兄台写错了。http://wiki.nginx.org/HttpLuaModule#ngx.statusngx.statuscontext: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*Read and write the current request's response status. This should be called before sending out the response headers. ngx.status = ngx.HTTP_CREATED status = ngx.statusSetting ngx.status after the response header is sent out has no effect but leaving an error message in your nginx's error log file: attempt to set ngx.status after sending out response headersOn Wed, Aug 26, 2015 at 9:58 AM, Hadals Yang <hadal...@gmail.com> wrote:大家好,我想利用状态码的值来做一些响应,但是ngx.var.status无法得到正确的值,全是0.请教下大家怎么回事啊? -- -- MembhisMy github: https://github.com/membphisOur Book: OpenResty Best Practices
谢谢解答,但是status = ngx.status还是得不到正确的值,比如404的情况得到是“0”在 2015年8月26日星期三 UTC+8上午10:49:00,YuanSheng Wang写道:兄台写错了。http://wiki.nginx.org/HttpLuaModule#ngx.statusngx.statuscontext: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*Read and write the current request's response status. This should be called before sending out the response headers. ngx.status = ngx.HTTP_CREATED status = ngx.statusSetting ngx.status after the response header is sent out has no effect but leaving an error message in your nginx's error log file: attempt to set ngx.status after sending out response headersOn Wed, Aug 26, 2015 at 9:58 AM, Hadals Yang <hadal...@gmail.com> wrote:大家好,我想利用状态码的值来做一些响应,但是ngx.var.status无法得到正确的值,全是0.请教下大家怎么回事啊? -- -- MembhisMy github: https://github.com/membphisOur Book: OpenResty Best Practices --
把你的代码写个最小集测试案例,确定可以复现问题。以及你的原始需求。现在初步怀疑你代码的执行阶段有问题。2015-08-26 11:15 GMT+08:00 Hadals Yang <hadal...@gmail.com>:谢谢解答,但是status = ngx.status还是得不到正确的值,比如404的情况得到是“0”在 2015年8月26日星期三 UTC+8上午10:49:00,YuanSheng Wang写道:兄台写错了。http://wiki.nginx.org/HttpLuaModule#ngx.statusngx.statuscontext: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*Read and write the current request's response status. This should be called before sending out the response headers. ngx.status = ngx.HTTP_CREATED status = ngx.statusSetting ngx.status after the response header is sent out has no effect but leaving an error message in your nginx's error log file: attempt to set ngx.status after sending out response headersOn Wed, Aug 26, 2015 at 9:58 AM, Hadals Yang <hadal...@gmail.com> wrote:大家好,我想利用状态码的值来做一些响应,但是ngx.var.status无法得到正确的值,全是0.请教下大家怎么回事啊? -- -- MembhisMy github: https://github.com/membphisOur Book: OpenResty Best Practices -- -- MembhisMy github: https://github.com/membphisOur Book: OpenResty Best Practices
#!/bin/env lualocal status = ngx.statusfile = io.open("/usr/local/nginx/conf/lua/lua.log","a")file:write(status)file:close()if status == "400" thenngx.redirect("http://www.xxx.com")endaccess_by_lua_file里面在 2015年8月26日星期三 UTC+8下午1:58:15,YuanSheng Wang写道:把你的代码写个最小集测试案例,确定可以复现问题。以及你的原始需求。现在初步怀疑你代码的执行阶段有问题。2015-08-26 11:15 GMT+08:00 Hadals Yang <hadal...@gmail.com>:谢谢解答,但是status = ngx.status还是得不到正确的值,比如404的情况得到是“0”在 2015年8月26日星期三 UTC+8上午10:49:00,YuanSheng Wang写道:兄台写错了。http://wiki.nginx.org/HttpLuaModule#ngx.statusngx.statuscontext: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*Read and write the current request's response status. This should be called before sending out the response headers. ngx.status = ngx.HTTP_CREATED status = ngx.statusSetting ngx.status after the response header is sent out has no effect but leaving an error message in your nginx's error log file: attempt to set ngx.status after sending out response headersOn Wed, Aug 26, 2015 at 9:58 AM, Hadals Yang <hadal...@gmail.com> wrote:大家好,我想利用状态码的值来做一些响应,但是ngx.var.status无法得到正确的值,全是0.请教下大家怎么回事啊? -- -- MembhisMy github: https://github.com/membphisOur Book: OpenResty Best Practices -- -- MembhisMy github: https://github.com/membphisOur Book: OpenResty Best Practices --
大家好,我想利用状态码的值来做一些响应,但是ngx.var.status无法得到正确的值,全是0.请教下大家怎么回事啊?