Chapter 14. Debugging and Troubleshooting with Access Logs, Error Logs, and Request Tracing

14.0 Introduction

Logging is the basis of understanding your application. With NGINX you have great control over logging information that is meaningful to you and your application. NGINX allows you to divide access logs into different files and formats for different contexts and to change the log level of error logging to get a deeper understanding of what’s happening. The capability of streaming logs to a centralized server comes innately to NGINX through its Syslog logging capabilities. NGINX also enables tracing of requests as they move through a system. In this chapter, we discuss access and error logs, streaming over the Syslog protocol, and tracing requests end to end with request identifiers generated by NGINX.

14.1 Configuring Access Logs

Problem

You need to configure access log formats to add embedded variables to your request logs.

Solution

Configure an access log format:

http {
  log_format  geoproxy 
              '[$time_local] $remote_addr '
              '$realip_remote_addr $remote_user '
              '$proxy_protocol_server_addr $proxy_protocol_server_port '
              '$request_method $server_protocol '
              '$scheme $server_name $uri $status '
              '$request_time $body_bytes_sent '
              '$geoip_city_country_code3 $geoip_region '
              '"$geoip_city" $http_x_forwarded_for '
              '$upstream_status $upstream_response_time '
              '"$http_referer" "$http_user_agent"';
  # ...
}

This log format configuration is named geoproxy and uses a number ...

Get NGINX Cookbook, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.