11user nginx;
22worker_processes auto;
33
4- error_log /var/log/nginx/error.log notice ;
4+ error_log /var/log/nginx/error.log warn ;
55pid /var/run/nginx.pid ;
66
77events {
@@ -12,28 +12,22 @@ http {
1212 include /etc/nginx/mime.types ;
1313 default_type application/octet-stream ;
1414
15- log_format path_status '$remote_addr - $remote_user [$time_local] $request $status' ;
15+ # Log format for errors (4xx and 5xx) - excludes successful requests
16+ # Dimensions: IP, timestamp, method, request URL (includes query string), status, referrer
17+ log_format errors_only '$remote_addr [$time_local] $request_method "$request_uri" $status "$http_referer"' ;
1618
17- # Debug log format - shows Host header details for troubleshooting routing issues
18- # To use, switch access_log below to use debug_routing instead of path_status
19- log_format debug_routing '$remote_addr [$time_local] "$request" '
20- 'status=$status '
21- 'host="$host" '
22- 'http_host="$http_host" '
23- 'server_name="$server_name" '
24- 'scheme=$scheme '
25- 'x_forwarded_host="$http_x_forwarded_host" '
26- 'x_forwarded_proto="$http_x_forwarded_proto"' ;
19+ # Map to conditionally log only 4xx and 5xx errors
20+ map $status $log_errors_only {
21+ ~ ^[45 ] 1;
22+ default 0;
23+ }
2724
28- access_log /var/log/nginx/access.log path_status ;
25+ access_log /var/log/nginx/access.log errors_only if = $log_errors_only ;
2926
3027 sendfile on;
31- #tcp_nopush on;
3228
3329 keepalive_timeout 65 ;
3430
35- #gzip on;
36-
3731 # Increase server_names_hash_bucket_size to handle long server names
3832 # Default is 64, but we have many long server_name entries
3933 server_names_hash_bucket_size 128 ;
0 commit comments