How to Monitor Nginx by using Stub Status Module on Ubuntu 21.04

To Monitor Nginx by using Stub Status Module on Ubuntu 21.04

Introduction:

The NGINX web server can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. In this module, you will find information about the basic status of the ngx_http_stub_status_context.

Installation Procedure:

Step 1: Check the OS version by using the below command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2: Install the Nginx by using the below command

root@linuxhelp:~# apt install nginx -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm11
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail
  libnginx-mod-stream libnginx-mod-stream-geoip2 nginx-common nginx-core
Suggested packages:
  fcgiwrap nginx-doc
The following NEW packages will be installed:
  libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail
  libnginx-mod-stream libnginx-mod-stream-geoip2 nginx nginx-common nginx-core
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.

Step 3: Check the status of the Nginx by using the below command

root@linuxhelp:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-01-22 04:44:06 IST; 25s ago
       Docs: man:nginx(8)
    Process: 9631 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 9632 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 9723 (nginx)
      Tasks: 3 (limit: 2254)
     Memory: 4.6M
     CGroup: /system.slice/nginx.service
             ├─9723 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─9726 nginx: worker process
             └─9727 nginx: worker process

Step 4: Check the Presence of stub_status module in Nginx by using the below command

root@linuxhelp:~# nginx -V 2>&1 | grep --color -- --with-http_stub_status_module
configure arguments: --with-cc-opt='-g -O2 -ffile-prefix-map=/build/nginx-DUpigx/nginx-1.18.0=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-DUpigx/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module

Step 5: Change the default server block with stub_status Module by using the below command

root@linuxhelp:~# vim /etc/nginx/sites-available/default 
server_name _;

        location /nginx_status {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                stub_status;
        }

Step 6: Reload the configurations of Nginx by using the below command

root@linuxhelp:~# service nginx reload

Step 7:Curl the following link to see status by using the below command

root@linuxhelp:~# curl http://127.0.0.1/nginx_status
Active connections: 1 
server accepts handled requests
 1 1 1 
Reading: 0 Writing: 1 Waiting: 0 

Step 8: Ping the http://127.0.0.1 in browser for testing purpose

Step 9: Curl the following link to see status by using the below command

root@linuxhelp:~# curl http://127.0.0.1/nginx_status
Active connections: 2 
server accepts handled requests
 3 3 5 
Reading: 0 Writing: 1 Waiting: 1 

By this to Monitor Nginx by using Stub Status Module on Ubuntu 21.04 has been completed

FAQ
Q
Does NGINX replace Apache?
A
Apache and Nginx are the two most common open source web servers in the world. ... While Apache and Nginx share many qualities, they should not be thought of as entirely interchangeable
Q
Why NGINX is so popular?
A
Nginx is popular due to its lightweight resource utilization and its ability to scale easily on minimal hardware.
Q
Which is better, Apache or NGINX?
A
Nginx is the Better because It performs 2.5 times faster than Apache according to a benchmark test running up to 1,000 simultaneous connections.
Q
How do we enable NGINX stub status?
A
Open your browser at http://127.0.0.1:8080/stub_status to access the status.
Q
Does the stub_status Module come by default?
A
Stub_status module is not built by default, it should be enabled with the --with-http_stub_status_module configuration parameter.