1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Nginx JSON Logging

Discussion in 'Random' started by sbagmeijer, Sep 10, 2014.

  1. sbagmeijer

    sbagmeijer Machine

    This post is again more a reminder for myself but it might help someone else :)

    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;
    Last edited: May 10, 2015

Share This Page