How to Monitor an Nginx Web Server
Nginx is the web server backbone that routes incoming HTTP traffic, resolves SSL handshakes, and load-balances backend application processes. If Nginx crashes, your entire site instantly goes offline with a connection timeout error.
This guide explains how to monitor Nginx web server uptime and map internal request volume and connection metrics to prevent server overload outages.
Step 1: Enable the Nginx Stub Status Module
Nginx has a built-in statistics module called ngx_http_stub_status_module that exposes current connection metrics on a secure endpoint.
Configure Nginx Server Block
Open your Nginx configuration file (e.g. /etc/nginx/sites-available/default) and add a status location block:
server {
listen 80;
server_name localhost;
location /nginx_status {
stub_status on;
# Restrict access so only authorized IPs can view connection metrics
allow 127.0.0.1;
# Add your local monitoring agent or office IP here:
# allow YOUR_OFFICE_IP;
deny all;
}
}
Reload Nginx to apply configurations:
sudo nginx -t && sudo systemctl reload nginx
Step 2: Check the Status Metrics
Curling your configured endpoint will return text metrics:
curl http://localhost/nginx_status
Output:
Active connections: 291
server accepts handled requests
16630 16630 31084
Reading: 6 Writing: 179 Waiting: 106
Explaining the Metrics:
- Active connections: The number of concurrent open client connections.
- accepts: Total number of accepted client connections.
- handled: Total number of handled connections (typically equal to accepts unless client limits are hit).
- requests: Total client request volume handled by Nginx.
- Reading: Number of headers Nginx is currently reading.
- Writing: Active body requests processed or sent back to clients.
- Waiting: Keep-alive connections idle waiting for requests.
Step 3: Monitor Uptime with Pingzo
To ensure Nginx responds quickly to incoming web traffic, configure active checks on Pingzo:
- Log in to your Pingzo Dashboard.
- Create an HTTP/HTTPS Monitor pointing to your website URL.
- Choose checker frequencies (down to 30 seconds for business critical paths).
- Configure custom alerts to receive instant notifications via WhatsApp or Slack if Nginx returns
502 Bad Gateway,504 Gateway Timeout, or goes offline completely.
Summarize with AI
Instantly generate a summary of this page using your favorite LLM