Changing the log format in NginX

Many know logformat from Apache server config. The same thing exists for Nginx.

To use X-Forwarded-For instead of $remote_addr in the logs, add the following to /etc/nginx/nginx.conf:

log_format   forwarded '"$http_x_forwarded_for" - $remote_user [$time_local]  $status '
            '"$request" $body_bytes_sent "$http_referer" '
            '"$http_user_agent"';

Next, set this format for the standard access log file:

access_log /var/log/nginx/access.log forwarded;

Categories:

Updated: