Monitoring Nginx with Prometheus: Configuration, Exporter Installation, and Dashboard Setup
This guide explains how to enable Nginx's stub_status module, install and run the Nginx Prometheus Exporter, configure Prometheus to scrape Nginx metrics, and visualize the data using Grafana, providing a complete monitoring solution for web services.
Nginx is a high‑performance web server widely used in many applications, and monitoring its health is essential for reliable operation.
1. Configure Nginx – Enable the stub_status module by adding a location block to the Nginx configuration:
location /stub_status {<br/> stub_status;<br/> access_log off;<br/>}After editing the config, reload Nginx to apply the changes: $ sudo nginx -t<br/>$ sudo nginx -s reload 2. Install Nginx Prometheus Exporter – Download the exporter binary, extract it, and start it with the address of 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<br/>$ mkdir nginx-prometheus-exporter<br/>$ tar -zxvf nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz -C nginx-prometheus-exporter<br/>$ cd nginx-prometheus-exporter<br/>$ ./nginx-prometheus-exporter -nginx.scrape-uri=http://192.168.214.100:80/stub_status3. Configure Prometheus – Add a scrape job for the exporter in prometheus.yml:
scrape_configs:<br/> - job_name: 'nginx'<br/> scrape_interval: 10s<br/> static_configs:<br/> - targets: ['localhost:9113']Restart Prometheus to load the new configuration:
$ prometheus --config.file /etc/prometheus/prometheus.yml &After a short wait, the Nginx metrics (e.g., nginx_connections_active, nginx_http_requests_total, nginx_up) become visible in the Prometheus web UI.
4. Visualize with Grafana – Connect Grafana to Prometheus, create dashboards, and display the collected Nginx metrics for real‑time monitoring.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
