如下配置: server { listen 8004; root html; location = /test1 { content_by_lua ' ngx.req.read_body() local args=ngx.req.get_post_args() ngx.say(args.id) '; } error_page 404 /50x; location = /50x { content_by_lua ' if ngx.var.request_method == "GET" then ngx.req.read_body() local args=ngx.req.get_post_args() ngx.say(args.id) end '; } } 当给http://xxx:8008/test post一个数据后,xxx:8004这段配置里没有/test这个location,那么会进入到404,在get /50x这个location里,会把原先的post数据也打印出来,是NGINX故意这样设计的,还是一个BUG?
对不起,少了一段 server { listen 8008; location / { proxy_pass http://10.68.150.4:8004; } } 2014/1/18 lhmwzy <lh...@gmail.com>: > 如下配置: > server { > listen 8004; > root html; > location = /test1 { > content_by_lua ' > ngx.req.read_body() > local args=ngx.req.get_post_args() > ngx.say(args.id) > '; > } > error_page 404 /50x; > location = /50x { > content_by_lua ' > if ngx.var.request_method == "GET" then > ngx.req.read_body() > local args=ngx.req.get_post_args() > ngx.say(args.id) > end > '; > } > } > > 当给http://xxx:8008/test > post一个数据后,xxx:8004这段配置里没有/test这个location,那么会进入到404,在get > /50x这个location里,会把原先的post数据也打印出来,是NGINX故意这样设计的,还是一个BUG?
如图所示 2014/1/18 lhmwzy <lh...@gmail.com> 对不起,少了一段 server { listen 8008; location / { proxy_pass http://10.68.150.4:8004; } } 2014/1/18 lhmwzy <lh...@gmail.com>: > 如下配置: > server { > listen 8004; > root html; > location = /test1 { > content_by_lua ' > ngx.req.read_body() > local args=ngx.req.get_post_args() > ngx.say(args.id) > '; > } > error_page 404 /50x; > location = /50x { > content_by_lua ' > if ngx.var.request_method == "GET" then > ngx.req.read_body() > local args=ngx.req.get_post_args() > ngx.say(args.id) > end > '; > } > } > > 当给http://xxx:8008/test > post一个数据后,xxx:8004这段配置里没有/test这个location,那么会进入到404,在get > /50x这个location里,会把原先的post数据也打印出来,是NGINX故意这样设计的,还是一个BUG?
Attachment: QQ截图20140118095622.jpg Description: JPEG image
刚才图咋没发上来2014/1/18 lhmwzy <lh...@gmail.com> 如图所示 2014/1/18 lhmwzy <lh...@gmail.com> 对不起,少了一段 server { listen 8008; location / { proxy_pass http://10.68.150.4:8004; } } 2014/1/18 lhmwzy <lh...@gmail.com>: > 如下配置: > server { > listen 8004; > root html; > location = /test1 { > content_by_lua ' > ngx.req.read_body() > local args=ngx.req.get_post_args() > ngx.say(args.id) > '; > } > error_page 404 /50x; > location = /50x { > content_by_lua ' > if ngx.var.request_method == "GET" then > ngx.req.read_body() > local args=ngx.req.get_post_args() > ngx.say(args.id) > end > '; > } > } > > 当给http://xxx:8008/test > post一个数据后,xxx:8004这段配置里没有/test这个location,那么会进入到404,在get > /50x这个location里,会把原先的post数据也打印出来,是NGINX故意这样设计的,还是一个BUG? --
Hello! 2014/1/17 lhmwzy: > > 当给http://xxx:8008/test > post一个数据后,xxx:8004这段配置里没有/test这个location,那么会进入到404,在get > /50x这个location里,会把原先的post数据也打印出来,是NGINX故意这样设计的,还是一个BUG? > 这个是期望的结果,因为请求还是同一个,只不过 error_page 发起了一个内部跳转,匹配了一下 location 而已。 你期望的是什么行为? Regards, -agentzh
Hello! 2014/1/17 lhmwzy: > > 当给http://xxx:8008/test > post一个数据后,xxx:8004这段配置里没有/test这个location,那么会进入到404,在get > /50x这个location里,会把原先的post数据也打印出来,是NGINX故意这样设计的,还是一个BUG? > 这个是期望的结果,因为请求还是同一个,只不过 error_page 发起了一个内部跳转,匹配了一下 location 而已。 你期望的是什么行为? Regards, -agentzh --
Hello! 2014/1/17 lhmwzy: > 嗯,请求是同一个,但由POST变成了GET,我的意思是是不是原来的POST数据,不能再带过来了? > 是有人在置疑这个,说这是一个坑,所以我过来问问 > 对于 error_page 触发的内部跳转,nginx 确实会把请求方法改写为 GET(见 nginx 核心中的 ngx_http_send_error_page 函数的定义)。请求体数据还是有的,否则你的例子也不会输出“4”这个请求体里的数据。 Regards, -agentzh
Hello! 2014/1/17 lhmwzy: > 嗯,请求是同一个,但由POST变成了GET,我的意思是是不是原来的POST数据,不能再带过来了? > 是有人在置疑这个,说这是一个坑,所以我过来问问 > 对于 error_page 触发的内部跳转,nginx 确实会把请求方法改写为 GET(见 nginx 核心中的 ngx_http_send_error_page 函数的定义)。请求体数据还是有的,否则你的例子也不会输出“4”这个请求体里的数据。 Regards, -agentzh --
Hello! 2014/1/18 lhmwzy: > 那么是故意这样的吗?不是设计上的BUG? > 从 nginx 的这部分代码上看,很可能是故意而为之的。因为不太可能因为粗心而在这里故意引入一小段改写 HTTP 请求方法的代码。 Regards, -agentzh