Operations 4 min read

Monitoring Nginx with Prometheus: Configuration, Exporter Setup, and Grafana Visualization

This tutorial demonstrates how to monitor Nginx using Prometheus by enabling the stub_status module, installing and running the Nginx Exporter, configuring Prometheus scrape jobs, and optionally visualizing the collected metrics in Grafana, providing a complete end‑to‑end monitoring solution.

DevOps Operations Practice
DevOps Operations Practice
DevOps Operations Practice
Monitoring Nginx with Prometheus: Configuration, Exporter Setup, and Grafana Visualization

Nginx is a high‑performance web server widely used in various sites and applications. To keep it running smoothly, it needs to be monitored and managed.

This article explains how to use Prometheus to monitor Nginx performance metrics, covering three main steps: enabling the stub_status module, installing and running the Nginx Exporter, and configuring Prometheus (and optionally Grafana) to collect and display the data.

1. Enable stub_status module

Add the following location block to the Nginx configuration to expose status information:

location /stub_status {
    stub_status;
    access_log off;
}

Reload Nginx configuration:

$ sudo nginx -t
$ sudo nginx -s reload

2. Install and start Nginx Exporter

Download and extract the exporter:

$ 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

Run the exporter, pointing it to the stub_status endpoint:

$ ./nginx-prometheus-exporter -nginx.scrape-uri=http://192.168.214.100:80/stub_status

3. Configure Prometheus

Add a scrape 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 (e.g., nginx_connections_active , nginx_http_requests_total , nginx_up ) become visible in the Prometheus web UI. These can be visualized in Grafana by adding Prometheus as a data source and creating dashboards.

MonitoringOperationsprometheusnginxGrafanaExporter
DevOps Operations Practice
Written by

DevOps Operations Practice

We share professional insights on cloud-native, DevOps & operations, Kubernetes, observability & monitoring, and Linux systems.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.