how to monitor nginx active connections2 min read

Prabhin Prabharkaran Administrator
DevOps Engineer

He is a Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!

follow me

Hi All, this document deals with how to monitor nginx active connections.
Nginx is one of the best open source web servers. It performs much faster than the Apache web server.
Nginx is a web server which can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004. A company of the same name was founded in 2011 to provide support and Nginx plus paid software.

nginx

So here is the configuration to see the connections detail of Nginx server

Step1: Open the Nginx configuration. In my case it is /etc/nginx/conf/nginx.conf.
For you it might be in /etc/nginx/sites-available/default.conf

Step 2: Add the following into the server block.

location /nginx_status {
# Turn on stats
stub_status on;
access_log off;
# only allow access from 192.168.1.5 #
allow 192.168.1.5;
deny all;
}

where /nginx_status is the URL path to see the connection details.
allow <IP> is the IP from which Nginx allows to see the connection details page.

deny all refer to deny all the request for this path other than the allowed IP address.

Step 3: Once the configuration is done, save and exit.
Step 4: Check the configuration using the below command

nginx -t

Expected Output.

nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

Step 5: Restart or reload the Nginx service.

service nginx restart
OR

service nginx reload
OR
/usr/sbin/nginx -s reload

If you want to Nginx connection status page to be running in a different port, use the below configuration.
Step 1: Create a new server block which runs on different port number. OR you can create a file with configuration under /etc/nginx/sites-available/

server {
listen 10061;
location /nginx_status {
stub_status on;
access_log off;
allow 18.138.235.243;
allow 172.31.0.159;
deny all;
}

}

Step 2: Check the configuration using the below command

nginx -t

Expected Output.

 

nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

Step 3: Restart or reload the Nginx service.

service nginx restart
OR

service nginx reload
OR
/usr/sbin/nginx -s reload

© 2019, Techrunnr. All rights reserved.

#1
#2
#3
Questions Answered
Articles Written
Overall Points

Related posts

Leave a Reply