Friday, December 26, 2014

Enabling the Nginx Status Page

If you've ever been curious about monitoring your web servers in addition to what's provided in the logs, you can turn turn on the nginx status page with a few simple steps. This status page provides valuable information about server usage, which is explained in the Nginx Http Status Module page. I've listed this information below, as well.

  • active connections -- number of all open connections including connections to backends
  • server accepts handled requests -- nginx accepted 16630948 connections, handled 16630948 connections (no one was closed just it was accepted), and handles 31070465 requests (1.8 requests per connection)
  • 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)

Prerequisites: You'll want to read up on Nginx server blocks. This guide was written for Mac OS X and Linux Ubuntu users.

Configuring Nginx

Installing Nginx with apt-get usually compiles it with the http stub status module. You can verify this by running the following command:

# grep nginx modules 
nginx -V 2<&1 | sed 's,–,n–,g' | grep stub_status

# look for this string in the output

Now rather than add the /nginx_status location to each server block for all of our domains, we're just going to add a new server block in one location, centralizing this page to http://x.x.x.x/nginx_status.

# create a new status.conf
sudo vi /etc/nginx/conf.d/status.conf

# with the following server block
server {
  listen 80 default_server;
  access_log off;
  server_name _;
  server_name_in_redirect off;

  location /nginx_status {
    stub_status on;

    # Do not log access queries for status page
    access_log   off;

    allow x.x.x.x;
    deny all;

If nginx fails on restart, make sure to tail your /var/log/nginx/error.log. Also take note that this is where we want to indicate default_server, not under any *.com domain.

No comments:

Post a Comment