Nginx is a free, open-source webserver, load balancer and reverses proxy program. One of the best things about it is that it supports both static and dynamic modules (introduced after v1.9.11).
The module we’re talking about, ngx_http_stub_status_module, enables a status page of sorts where you can check different metrics about your web server, such as active traffic, incoming connections and number of requests, among other things.
Also read: How to display line number in Vi editor?
How to enable Nginx status module?
On most Linux distros, the module is already enabled. However, you can check this for your specific machine using the following command.
nginx -V 2>&1 | grep -o with-http_stub_status_module
If you don’t see any output in the terminal, you’re going to have to compile Nginx from source with the –with-http_stub_status_module as a configuration parameter. Just enter the following commands one by one and press enter after each one.
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
Once you’ve Nginx up and running with the module enabled, we can get on to enabling the status page.
Also read: Linux no space left on device: 3 Fixes
Enabling the Nginx status page
Now to enable the Nginx status page, you enable the page itself in the Nginx config file and set up a URL to access the page.
Just add the following snippet to the Nginx configuration file. The file is usually located in /etc/nginx/nginx.conf. However, depending on your Linux distro or settings, it might be located in a different location.
location /nginx_status { stub_status; allow 127.0.0.1; #only allow requests from localhost. Make sure to replace this with your locahost address deny all; #deny all other hosts }
Now restart the Nginx service for the changes to take effect by using the following command.
nginx -s reload
Once the service has restarted, use curl to visit the status page.
curl http://127.0.0.1/nginx_status
Or
curl http://example.site/nginx_status
Also read: Passwd: authentication token manipulation error: 6 Fixes