Nginx - Log (log_format)

About

This article is about the Web/HTTP log of nginx.

The log is:

Example of specific log format

This log format include response times.

  • Definition
log_format mtail '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent $request_time '
                 '"$http_referer" "$http_user_agent" "$content_type" "$upstream_cache_status"';
  • then the access logs format needs to be enabled in each server section:
access_log /var/log/nginx/mtail/access.log mtail;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

Default

If the format is not specified then the predefined “combined” format is used.

log_format combined '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';

Powered by ComboStrap