enable status page in nginx

How To Enable NGINX Status Page

NGINX web server offers ngx_http_stub_status_module module that allows you to easily monitor server health. NGINX status page displays many useful server KPI metrics such as no. of active client connections, accepted, handled & total requests. It also shows reading, writing, and waiting connections. We will look at how to enable NGINX status page for your NGINX server.


How to Enable NGINX status page

Here are the steps to enable NGINX status page.


1. Check if NGINX status page is enabled

Most NGINX distributions come with ngx_http_stub_status_module module enabled. You can check if it is enabled in your NGINX installation using the following command

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

If you see –with-http_stub_status_module output, it means the status module is already enabled.

Otherwise you will need to compile NGINX from source along with status module. Here are the commands to compile NGINX with –with-http_stub_status_module

# wget http://nginx.org/download/nginx-1.13.12.tar.gz 
# tar xfz nginx-1.13.12.tar.gz 
# cd nginx-1.13.12/ 
# ./configure --with-http_stub_status_module 
# make 
# make install

Bonus Read : How to Install Varnish for NGINX

2. Enable status page

We will enable NGINX status page by setting up a URL (e.g /status_page) for status page. For this, add a location block in NGINX server configuration as shown below.

Open terminal and run the following command to open NGINX server configuration file.

$ sudo vi /etc/nginx/nginx.conf

If you have configured separate virtual hosts for your website (e.g www.example.com), such as /etc/nginx/sites-enabled/website.conf then open its configuration with the following command

$ sudo vi /etc/nginx/sites-enabled/website.conf

Add the following location block that will enable stub_status module

location /nginx_status { 
          stub_status; 
          allow 127.0.0.1; #only allow requests from localhost
          deny all; #deny all other hosts 
}

Replace 127.0.0.1 above with your server’s IP address (e.g 54.45.23.21). So your server block will look like

server {
...
      location /nginx_status {
        stub_status;
        allow 54.45.23.21; #only allow requests from localhost
        deny all; #deny all other hosts
       }
...
}

Bonus Read : Step by Step NGINX SSL configuration

3. Restart NGINX Server

Run the following command to check syntax of your updated config file.

$ sudo nginx -t

If there are no errors, run the following command to restart NGINX server.

$ sudo service nginx reload #debian/ubuntu
$ systemctl restart nginx #redhat/centos

Bonus Read : How to Prevent Image Hotlinking in NGINX

4. Test NGINX Status Page

Run the following command to visit your status page URL using curl command. Replace 127.0.0.1 with your server IP or domain name

# curl http://127.0.0.1/nginx_status 
OR 
# curl http://www.example.com/nginx_status

You will see a similar output with server metrics.

Hopefully the above tutorial will help you enable status page in NGINX. Please note ngx_http_stub_status_module module has been replaced by ngx_http_api_module module since Nginx 1.13.0 version.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!