How to log POST data in Nginx

NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

By default, NGINX doesn't log POST data, as it can be very bulky which may lead to disk space shortage issues. However, there are certain situations where getting access to this data is vital to debugging issues.

This article explains the details to configure Nginx to log POST data.

Inorder to achieve this open nginx.conf and add the following lines.

log_format post_logs '[$time_local] "$request" $status '  

                     '$body_bytes_sent "$http_referer" '        

                     '"$http_user_agent" [$request_body]';

access_log  /var/log/nginx/postdata-access.log post_logs;

Then restart Nginx service.

That's all……

Leave a Reply