Enable Nginx Stub Status
server {
listen 127.0.0.1:8080;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}Install Nginx Exporter
wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v1.1.0/nginx-prometheus-exporter_1.1.0_linux_amd64.tar.gz
tar xzf nginx-prometheus-exporter_*.tar.gz
sudo mv nginx-prometheus-exporter /usr/local/bin/Create Systemd Service
[Unit]
Description=Nginx Prometheus Exporter
After=network.target
[Service]
ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri=http://127.0.0.1:8080/nginx_status
Restart=always
[Install]
WantedBy=multi-user.targetAdd to Prometheus
scrape_configs:
- job_name: "nginx"
static_configs:
- targets: ["localhost:9113"]Grafana Dashboard
Import dashboard ID 12708 in Grafana for a pre-built Nginx overview. Key metrics to track:
- Active connections — current client connections
- Request rate — requests per second
- Response status codes — 2xx, 4xx, 5xx distribution