12.7. Nginx Prometheus Exporter

12.7.1. Download nginx-prometheus-exporter

  • Download

  • Extract

  • Copy to /usr/local/bin

  • Set ownership and permissions

# mkdir -p /tmp/nginx_exporter_tmp && cd /tmp/nginx_exporter_tmp
# wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v1.2.0/nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz
# tar axf nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz
# cd nginx-prometheus-exporter
# cp nginx-prometheus-exporter /usr/local/bin

12.7.2. Create a system user

# useradd --system --no-create-home --shell /bin/false nginx-exporter

12.7.3. Systemd configuration Nginx-prometheus-exporter systemd service file

# Path:/etc/systemd/system/nginx-exporter.service

Description=NGINX Prometheus Exporter

ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri="" --web.systemd-socket

WantedBy=multi-user.target Nginx-prometheus-exporter systemd socket file

# Path: /etc/systemd/system/nginx-exporter.socket

Description=NGINX Prometheus Exporter



12.7.4. Modify the Prometheus configuration file

# Path: /etc/prometheus/prometheus.yml

# Job, for nginx_exporter
  - job_name: 'nginx_exporter'
      - targets: ['localhost:9113'] # choose port number

12.7.5. Nginx configuration

server {
   listen localhost;
   root /var/www/html;
   index index.html;
   server_name _;

   location /metrics {
      stub_status on;
      access_log off;
      deny all;


## Create the Nginx symbolic link to enable the virtualhost file
# ln -s /etc/nginx/sites-available/nginx-exporter.conf /etc/nginx/sites-enabled/nginx-exporter.conf
# nginx -t
# systemctl reload nginx
## Check with curl
# curl http://localhost/metrics

12.7.6. Restart everything

# systemctl daemon-reload # Only necessary if modified
# systemctl enable --now node-exporter.service
# systemctl status node-exporter.service
# systemctl restart prometheus.service

12.7.7. Close the 9113 port with Nginx

  • Change the nginx-exporter.socket file

# Path: /etc/systemd/system/nginx-exporter.socket

Description=NGINX Prometheus Exporter

# Add here the loopback ip address


12.7.8. Add a new server block to Nginx

server {
 listen 80;
 listen [::]:80;

 server_name ip_address | subdomain.ltd;
     location /nginx-exporter {
       proxy_pass http://localhost:9113;


12.7.9. Create a new dashboard in Grafana

You can now go to the Grafana dashboards and easily add the new dashboard for the Nginx Exporter program. Please make sure you choose the right Prometheus data source.