0
0
NginxHow-ToBeginner · 4 min read

How to Monitor Nginx Performance: Simple Steps and Examples

To monitor nginx performance, enable the stub_status module to get basic metrics like active connections and requests. Use access logs for detailed request data and tools like NGINX Amplify or Grafana with Prometheus for advanced real-time monitoring and visualization.
📐

Syntax

The stub_status module provides a simple way to check Nginx performance metrics. You enable it inside a server block with the location /nginx_status directive. This setup shows active connections, accepted connections, handled connections, and requests.

Example parts explained:

  • location /nginx_status: URL path to access status info.
  • stub_status;: directive to enable status output.
  • allow 127.0.0.1;: restricts access to localhost for security.
  • deny all;: denies access from other IPs.
nginx
server {
    listen 80;
    server_name localhost;

    location /nginx_status {
        stub_status;
        allow 127.0.0.1;
        deny all;
    }
}
💻

Example

This example shows how to enable the stub_status page and how to query it using curl to see live performance data.

bash
server {
    listen 8080;
    server_name localhost;

    location /nginx_status {
        stub_status;
        allow 127.0.0.1;
        deny all;
    }
}

# After reloading nginx, run:
curl http://127.0.0.1:8080/nginx_status
Output
Active connections: 5 server accepts handled requests 1000 1000 1500 Reading: 0 Writing: 1 Waiting: 4
⚠️

Common Pitfalls

Common mistakes when monitoring Nginx performance include:

  • Not restricting access to the stub_status page, exposing sensitive data publicly.
  • Forgetting to reload Nginx after configuration changes.
  • Relying only on stub_status which provides limited metrics.
  • Ignoring log analysis which is crucial for detailed request insights.

Always combine stub_status with log monitoring and consider tools like Prometheus exporters for full metrics.

nginx
location /nginx_status {
    stub_status;
    # Missing access control - insecure!
    # allow 127.0.0.1;
    # deny all;
}
📊

Quick Reference

Summary tips for monitoring Nginx performance:

  • Enable stub_status for basic metrics.
  • Use access_log for detailed request data.
  • Protect status endpoints with IP restrictions.
  • Use monitoring tools like NGINX Amplify, Prometheus, and Grafana for advanced insights.
  • Regularly analyze logs and metrics to detect issues early.

Key Takeaways

Enable the stub_status module to get quick Nginx performance metrics.
Protect the status page with IP restrictions to avoid exposing data.
Use access logs alongside stub_status for detailed monitoring.
Leverage tools like Prometheus and Grafana for real-time visualization.
Regularly review logs and metrics to maintain Nginx health.