Lesson 9 of 9 · 22m
Observability and Day-Two Operations
Logging the timing data that matters, reading error signals correctly, exposing basic status safely, and building operational habits around nginx.
When nginx is healthy, nobody thinks about it. When it is unhealthy, everyone asks questions the default logs cannot answer: Was the client slow or the backend? Was the response generated upstream or served from cache? Which upstream timed out? Did the request even reach the application? Day-two nginx administration means making those answers cheap before the incident.
Log timing and upstream identity
The default combined format is fine for traffic archaeology and terrible for diagnosing proxy behavior. Add structured fields:
log_format proxy_timing json_escape=escaped
'{"time":"$time_iso8601","remote":"$remote_addr",'
'"method":"$request_method","host":"$host","uri":"$request_uri",'
'"status":$status,"bytes":$body_bytes_sent,"request_time":$request_time,'
'"upstream":"$upstream_addr","upstream_status":"$upstream_status",'
'"connect_time":"$upstream_connect_time","header_time":"$upstream_header_time",'
'"response_time":"$upstream_response_time","cache":"$upstream_cache_status"}';
access_log /var/log/nginx/app-access.log proxy_timing;Now a single line answers the classic split-brain incident. High request_time with low upstream times often means slow client reading. High upstream_connect_time points toward network or backlog trouble. Repeated comma-separated upstreams mean retries happened.
Read errors as symptoms, not verdicts
upstream timed out (110: Connection timed out) while reading response header
connect() failed (111: Connection refused) while connecting to upstream
no live upstreams while connecting to upstream
client intended to send too large bodyConnection refused means the backend socket is not accepting — process down, wrong port, firewall rejection. Connection timed out means packets are disappearing or the host cannot respond — network, backlog, firewall drop. They are not interchangeable. no live upstreams means nginx currently believes every peer is unusable, often due to passive failure marking.
Expose status narrowly
stub_status provides basic counters:
location = /nginx-status {
stub_status;
allow 10.20.0.0/16;
allow 127.0.0.1;
deny all;
}It reports active connections, accepts, handled requests, and reading/writing/waiting counts. Useful, but not deep observability. For serious metrics, use an exporter that parses logs, nginx-plus API if licensed, or sidecar telemetry. Whatever you choose, never expose status publicly.
Build small operating rituals
awk -F'"status":' '{print $2}' /var/log/nginx/app-access.log | cut -d, -f1 | sort | uniq -c | sort -nr
nginx -T | grep -E 'server_name|listen'The point is not the exact shell incantation. It is that operators should know where logs live, what normal status distribution looks like, which server blocks own which traffic, and how quickly errors correlate with deploys. Install log rotation carefully: nginx needs a reopen signal or copy-truncate-aware handling depending on your logging setup.
Field notes
$request_timemeasures the whole client interaction, so it includes slow clients; upstream timings isolate backend behavior.- A comma in
$upstream_addrmeans multiple upstreams were tried — treat it as a retry signal. - Log volume is part of capacity planning; detailed JSON logs can dominate disk I/O on high-traffic nodes.
- Debug logging is extremely noisy; scope it narrowly and never leave it globally enabled.
Was this lesson helpful?