Log POST data in nginx

How to configure nginx to log POST data in nginx?

NGINX is a powerful web server that can easily tens of thousands of  HTTP requests per second with minimum CPU consumption. Each time NGINX handles a connection, a log entry is generated to store some information this connection like remote IP address, response size and status code, etc. In some cases, you may be more interested in storing the body of requests, specifically POST requests. In this article we will explain how to enable POST data logging in nginx

We will use the $request_body log parameter to log the actual POST data of the incoming request. Nginx configuration will look like this

1 2 3 4 5 6 7 8 9 10 11   location / {   log_format postdata $request_body; access_log /mnt/logs/nginx/my_tracking.access.log postdata; ## You can add remaining config options here ## ###   }  

Restart nginx service once changes are made in config file

You will be able to see the logs here in the log

1 2 3   /var/log/nginx/nginx_post_data.log  

 

Author: , 0000-00-00