NGINX Server Configuration

This package supports three different types of NGINX log data:

  • The error logs with default formatting

  • The default combined format for access logs (though some widgets will be missing data with this format)

  • A custom key-value based format for access logs

For access logs, the key-value format is our recommended log format, as it both includes all data expected by the included dashboards, but is also the easiest to extend with new data. If you wish to change how the access logs are formatted by NGINX, you can follow the guide below.

If you would like to log more fields or log with a different format, you can see the Extending Parsers for Custom Access Logs section further down for how to change parsers and log formats while remaining compatible with the contents of this package.

Configuring Log Formats

To enable the suggested custom formats please make the changes as described below. The changes should be made in the configuration file located in: /etc/nginx/nginx.conf

Now, configure NGINX to use the defined custom log format.

Use server{ } tag in http{ } tag to configure server.

Define server name, port, access log file name and location of html file.

You can can configure multiple servers in NGINX using multiple server{ } within http{ } Refer to Configuring Logging for help with configuring NGINX logs and to Variable index for other NGINX log variables.

json
http {
  ...
  log_format main 'timestamp="$time_local" server_name="$server_name" server="$host" '
        'dest_port="$server_port" dest_ip="$server_addr" '
        'method="$request_method" url="$request_uri" userid="$remote_user" '
        'status="$status" src="$remote_addr" src_port="$remote_port" '
	    'protocol="$server_protocol" '
        'bytes_sent="$bytes_sent" body_bytes_sent="$body_bytes_sent" bytes_received="$upstream_bytes_received" '
        'referer="$http_referer" https="$https" '
        'user_agent="$http_user_agent"';

  server {
    ...
    access_log /var/log/nginx/access.log main;
    server_name server1;
    ...
  }
  ...
}

Combined format example:

http {
  ...
  log_format main  '$remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';

  server {
    ...
    access_log /var/log/nginx/access.log main;
    server_name server1;
    ...
  }
  ...
}