Tips & Tricks

How to make Nginx log in JSON format

To get Nginx to log in JSON format you have to add the following to “nginx.conf” under the http bit:
log_format json '{ "@timestamp": "$time_iso8601", '
'"message": "$remote_addr - $remote_user [$time_local] \\\"$request\\\" $status $body_bytes_sent \\\"$http_referer\\\" \\\"$http_user_agent\\\"", '
'"tags": ["nginx_access"], '
'"realip": ""$remote_addr", '
'"proxyip": "$http_x_forwarded_for", '
'"remote_user": "$remote_user", '
'"contenttype": "$sent_http_content_type", '
'"bytes": $body_bytes_sent, '
'"duration": "$request_time", '
'"status": "$status", '
'"request": "$request", '
'"method": "$request_method", '
'"referrer": "$http_referer", '
'"useragent": "$http_user_agent" }';

and then in your vhost configuration you add the following line:
access_log /var/log/nginx/access.json json;

Related posts

AWS Cli Commands to remember

Sjir Bagmeijer

Nginx SSL example

Sjir Bagmeijer

MacBook Air (mid 2011) bootcamp Windows 8.1 enterprise wifi fix

Sjir Bagmeijer

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More