diff --git a/tools/reverse-proxy/nginx.conf b/tools/reverse-proxy/nginx.conf index 8ba39f0..2304efc 100644 --- a/tools/reverse-proxy/nginx.conf +++ b/tools/reverse-proxy/nginx.conf @@ -12,17 +12,30 @@ http { include /etc/nginx/mime.types; default_type application/octet-stream; - # Log format for errors (4xx and 5xx) - excludes successful requests - # Dimensions: IP, timestamp, method, request URL (includes query string), status, referrer - log_format errors_only '$remote_addr [$time_local] $request_method "$request_uri" $status "$http_referer"'; + # Log format - includes IP, timestamp, method, URL, status, referrer + log_format main '$remote_addr [$time_local] $request_method "$request_uri" $status "$http_referer"'; - # Map to conditionally log only 4xx and 5xx errors - map $status $log_errors_only { + # Map to identify errors (4xx/5xx) + map $status $is_error { ~^[45] 1; default 0; } - access_log /var/log/nginx/access.log errors_only if=$log_errors_only; + # Map to identify healthcheck requests + map $request_uri $is_healthcheck { + ~^/ops/healthcheck 1; + default 0; + } + + # Combine: log if error OR healthcheck + map "$is_error:$is_healthcheck" $should_log { + "1:0" 1; + "1:1" 1; + "0:1" 1; + default 0; + } + + access_log /var/log/nginx/access.log main if=$should_log; sendfile on;