Backup

Take a backup of your existing nginx.conf before you make changes to it

cp /etc/nginx/nginx.conf /etc/nginx/backup_nginx.conf

Custom NGINX access log

  1. Edit the NGINX configuration file (/etc/nginx/nginx.conf by default) and use the log_format directive to define the format of access logs.

  2. Replace the existing/default log_format with the below format

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" $request_time '
    

Save & Reload

  1. Save the nginx.conf file
  2. Reload the Nginx service

Validate

Check your nginx logs to ensure that they are being logged in the above json format.