Nginx – echo_read_request_body doesn’t work. How to log POST request body (nginx)

loggingnginx

I need to log POST data.
I have added to my config

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

And also added this to http section

log_format  postdata '$time_local $request_body';

But in my log I can see only local time and dash:

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

What's the problem?

Best Answer

I was having the same problem: no post data were being logged. I fixed my problem by ensuring the endpoint returned something. The following worked for me:

location /log {
    echo_read_request_body;
    access_log /var/log/nginx/postdata.log postdata;
    default_type text/html;
    echo "POST";
}

The key is:

  1. set the Content-Type headers with default_type
  2. provide some content in the response with echo
Related Topic