Chapter 14. Debugging and Troubleshooting with Access Logs, Error Logs, and Request Tracing
Introduction
Logging is the basis of understanding your application. With NGINX you have great control over logging information 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. 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.
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 ' '$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 of embedded variables to demonstrate the power of NGINX logging. This configuration shows the local time on the server ...
Get NGINX Cookbook 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.