How-to guide
Nginx monitoring: status, logs and alerts
Nginx sits in front of almost everything. Its status page and access logs tell you how much traffic arrives, how much fails and how long your upstreams take.
4 min read13 sectionsUpdated
On this page
| Field | Meaning | Watch for |
|---|---|---|
| Active connections | Open client connections | Sudden jumps (traffic or slow upstreams) |
| accepts vs handled | Accepted vs handled connections | handled < accepts means dropped (worker_connections limit) |
| requests | Total requests | Rate over time = requests per second |
| Reading / Writing / Waiting | States of current connections | High Writing = slow responses or slow clients |
log_format json_combined escape=json '{'
'"time":"$time_iso8601","remote":"$remote_addr","method":"$request_method",'
'"uri":"$uri","status":$status,"bytes":$body_bytes_sent,'
'"request_time":$request_time,"upstream_time":"$upstream_response_time",'
'"upstream":"$upstream_addr","ua":"$http_user_agent"}';
access_log /var/log/nginx/access.json json_combined;With JSON logs you can chart the 5xx share per route, upstream time percentiles, and which upstream instance is slow, and search individual requests during an incident. Ship them with your log aggregation pipeline.
In VitalRix
A ready-made Nginx check reads the stub_status page on a schedule and alerts on dropped or saturated connections. Uptime monitoring checks the public URLs, and logs take the JSON access log for search and live tail.
| Setting | What it limits | Symptom when too low |
|---|---|---|
| worker_processes | Number of worker processes | CPU-bound workers; set to auto |
| worker_connections | Connections per worker | accepts > handled in stub_status |
| worker_rlimit_nofile | Open files per worker | "too many open files" in the error log |
| keepalive_timeout | Idle client connections | Many Waiting connections holding slots |
| proxy_read_timeout | Time waiting for the upstream | 504 errors |
Useful log queries
With JSON access logs in a log search tool, these answer most questions during an incident: 5xx responses by route in the last 15 minutes; the slowest requests by upstream_time; requests per upstream address (is one backend misbehaving?); and the top client IPs and user agents (is this a bot or a retry storm?).
The NGINX metrics that matter
stub_status gives connection counts; the access log, with the right fields, gives everything else.
| Metric | Source | Starting alert |
|---|---|---|
| Active connections | stub_status | Near worker_processes × worker_connections |
| accepts vs handled | stub_status | Any difference: connections were dropped at a limit |
| 5xx rate | Access log status | Above 1% for 5 minutes |
| Request time and upstream time | $request_time, $upstream_response_time | p95 above your budget |
| Upstream errors | Error log: "upstream timed out", "connect() failed" | Any burst |
# a small status endpoint, local only
location = /nginx_status { stub_status; allow 127.0.0.1; deny all; }
# log how long each request and its upstream took
log_format timed '$remote_addr "$request" $status $body_bytes_sent '
'rt=$request_time urt=$upstream_response_time ua="$http_user_agent"';
access_log /var/log/nginx/access.log timed;What the incidents look like
- 502 Bad Gateway when the upstream (PHP-FPM, Node.js, a container) is down or crashes mid-response: see 502 Bad Gateway.
- 504 Gateway Timeout when the upstream is alive but slower than proxy_read_timeout: see 504 Gateway Timeout.
- Connections hit worker_connections under a traffic spike or many slow clients; accepts and handled diverge. Raise the limit together with the file descriptor limit.
- A reload with a broken config after an edit. Always run
nginx -tfirst, and keep an uptime check on the public URL so a bad reload is caught in a minute.
Is stub_status safe to expose?
Keep it on localhost or an internal port with allow and deny rules. It reveals traffic levels, which you may not want public.
What does upstream_response_time "-" mean?
Nginx did not contact an upstream for that request, such as a static file or a cached response.
Related reading
- MySQL monitoring: key metrics and alerts: Monitor MySQL: connections and threads, query throughput, slow queries, InnoDB buffer pool, replication lag and disk, with the SQL for each check.
- The three pillars of observability: Logs, metrics and traces compared: what each pillar of observability is good at, what it costs, and how to link them so one alert leads to the cause.
- PostgreSQL monitoring: key metrics and alerts: Monitor PostgreSQL: connections, slow queries, locks, replication lag, cache hit ratio, bloat and disk, with the SQL for each and the alerts to set.
- Kubernetes observability: Kubernetes observability for application teams: pod resources against limits, restarts and OOM kills, and traces with Kubernetes metadata.
- 403 Forbidden: what it means and how to fix it: Fix 403 Forbidden errors: file permissions, missing index files, WAF and bot rules, IP allowlists, expired signed URLs and missing API scopes, step by step.
- How to set a log retention policy: Decide how long to keep logs, traces and metrics: debugging needs, security and compliance, cost, tiered retention and a sample policy to adapt.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.