Monitoring Nginx with Prometheus: Configuration and Visualization Guide
This tutorial shows how to enable Nginx's stub_status module, install the Nginx Prometheus Exporter, configure Prometheus to scrape Nginx metrics, and visualize the data in Grafana, providing a complete end‑to‑end monitoring solution.
Nginx is a high‑performance web server that often requires monitoring to ensure reliable operation.
This guide explains how to use Prometheus to collect Nginx performance metrics.
1. Enable the stub_status module
Add a location block to the Nginx configuration:
location /stub_status {
stub_status;
access_log off;
}Reload Nginx to apply the changes:
$ sudo nginx -t
$ sudo nginx -s reload2. Install Nginx Exporter
Download and extract the exporter binary, then start it pointing to the stub_status endpoint:
$ wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.11.0/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz
$ mkdir nginx-prometheus-exporter
$ tar -zxvf nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz -C nginx-prometheus-exporter
$ cd nginx-prometheus-exporter
$ ./nginx-prometheus-exporter -nginx.scrape-uri=http://192.168.214.100:80/stub_status3. Configure Prometheus
Add a job for the exporter in prometheus.yml :
scrape_configs:
- job_name: 'nginx'
scrape_interval: 10s
static_configs:
- targets: ['localhost:9113']Restart Prometheus:
$ prometheus --config.file /etc/prometheus/prometheus.yml &After a short wait, the Nginx metrics appear in the Prometheus web UI. Example queries include nginx_connections_active , nginx_http_requests_total , and nginx_up .
Optionally, import these metrics into Grafana to build dashboards for visual monitoring.
DevOps Operations Practice
We share professional insights on cloud-native, DevOps & operations, Kubernetes, observability & monitoring, and Linux systems.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.