Last updated on August 27th, 2024 at 04:38 am
When you run a website, it is important to regularly monitor the status of your web server. It helps us understand if our server is overloaded and how it is performing. NGINX is a popular web server that is free, scalable and enjoys a wide user base. It offers several modules such as 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.
What is NGINX Status Page
Every NGINX server supports ngx_http_stub_status_module that allows you to view server metrics on HTTP/HTTPS web pages. It helps you to monitor important information such as number of connections, requests, response codes, etc. that help site administrators understand server load. It provides live information that can be automatically refreshed. In many cases, this server status page is disabled by default. You can check it with the following command.
# nginx -V 2>&1 | grep -o with-http_stub_status_module
with-http_sub_status_module
Please note ngx_http_stub_status_module module has been replaced by ngx_http_api_module module since Nginx 1.13.0 version. So you will need to use the following command for new NGINX servers.
# nginx -V 2>&1 | grep -o with-http_api_module
with-http_sub_status_module
How to Enable NGINX status page
Here are the steps to enable NGINX status page.
1. Check if NGINX status page is enabled
The status page module needs to be included during NGINX installation. For this purpose, you will need to compile NGINX from source along with status module. It cannot be added once NGINX is installed. 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
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
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.
Add the following location block that will enable stub_status module. You can change the URL /nginx_status to something else as per your requirement.
location /nginx_status {
stub_status;
}
The above configuration will allow anyone from anywhere to request /nginx_status. So add the following lines to allow requests only from localhost and nowhere else.
location /nginx_status {
stub_status;
allow 127.0.0.1;
deny all;
}
If you want to allow a trusted external IP, you can also include it as per your requirement.
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 127.0.0.1;
allow 54.45.23.21;
deny all;
}
...
}
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.
Conclusion
In this article, we have learnt what is NGINX status page, and how to enable it. NGINX status page provides a single point for many useful server metrics. It is important to enable it to regularly monitor your NGINX server and ensure that it does not get overloaded. Hopefully the above tutorial will help you enable status page in NGINX.
Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!
Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI & software development.