Enable Nginx Status Page

0
619

Nginx status page can give realtime data about Nginx’s health. It can help you tweak few Nginx config. Status data can be used in load-balancer env also.

Requirement

Nginx must be compiled with HttpStubStatusModule module. You can check that by running following command:

nginx -V 2>&1 | grep -o with-http_stub_status_module

If you see following output, you are good to go ahead. Otherwise, refer this post to install nginx-full.

with-http_stub_status_module

Nginx Config

You need to add following to a nginx site, say example.com, inside server {..} block.

        location /nginx_status {
          stub_status on;
          access_log   off;
          allow 1.1.1.1;
          deny all;
        }

Make sure you replace 1.1.1.1 with your machine’s IP-address. It’s good idea to keep this page accessible to only you.

Output:

Once you codes and reload nginx config, just visit: http://example.com/nginx_status You will see output like below:

Active connections: 43 
server accepts handled requests
 7368 7368 10993 
Reading: 0 Writing: 5 Waiting: 38

Interpretation

  • Active connections – Number of all open connections. This doesn’t mean number of users. A single user, for a single pageview can open many concurrent connections to your server.
  • Server accepts handled requests – This shows three values.
    • First is total accepted connections.
    • Second is total handled connections. Usually first 2 values are same.
    • Third value is number of and handles requests. This is usually greater than second value.
    • Dividing third-value by second-one will give you number of requests per connection handled by Nginx. In above example, 10993/7368, 1.49 requests per connections.
  • Reading – nginx reads request header
  • Writing – nginx reads request body, processes request, or writes response to a client
  • Waiting – keep-alive connections, actually it is active – (reading + writing).This value depends on keepalive-timeout. Do not confuse non-zero waiting value for poor performance. It can be ignored. Although, you can force zero waiting by setting keepalive_timeout 0;

LEAVE A REPLY

Please enter your comment!
Please enter your name here