echo_read_request_body不起作用。 如何loggingPOST请求正文(nginx)?

我需要loggingPOST数据。 我已经添加到我的configuration

location / { echo_read_request_body; access_log /var/log/nginx/domains/site.post.log postdata; } 

也join到http部分

 log_format postdata '$time_local $request_body'; 

但在我的日志中,我只能看到当地时间和短跑:

 23/Jul/2016:16:07:49 +0000 - 

有什么问题?

默认情况下,Nginx没有包含echo_read_request_body的模块。 你需要用模块自己编译它。

在我们的用例中,为了logging请求主体,我们需要使用echo_read_request_body命令和$request_bodyvariables(包含Echo模块的请求主体)。 但是,这个模块默认不会与NGINX一起发布,为了能够使用它,我们必须使用包含Echo模块的源代码来构buildNGINX的源代码。“

https://developers.redhat.com/blog/2016/05/23/configuring-nginx-to-log-post-data-on-linux-rhel/

 location = / { log_format postdata $request_body; access_log /var/log/nginx/domains/site.post.log postdata; fastcgi_pass php_cgi; } 

nginx并没有触及客户端请求体,除非必须,否则它不符合$ request_bodyvariables,但有一些例外情况1)如果它发送请求到代理2)或fastcgi服务器。 所以在上面的例子中,诀窍是nginx相信你会调用一个cgi脚本。