Publish: 2019-06-03 | Modify: 2019-06-04
More and more projects in the production environment are using Nginx as a web server. At the same time, we need to constantly monitor the status of Nginx, such as checking the current number of concurrent connections to ensure normal operation. This article shares two methods to view the number of concurrent connections in Nginx.
Method 1: View through the web interface
This method relies on the http_stub_status_module
module of Nginx. You can use the command nginx -V
to check if this module is installed. If it is not installed, you need to recompile Nginx with this module.
Add the following configuration inside any server block:
location /status {
stub_status on;
}
After modifying the configuration, use the command nginx -t
to ensure there are no syntax errors, and then reload the Nginx configuration with nginx -s reload
to make it effective. Then access http://youdomain.com/status
to see the connection status, as shown in the screenshot below.
The meanings of the above parameters are as follows:
Method 2: Command-line view
If you only want to view the current number of concurrent connections in Nginx without more detailed information, you can use the following command (netstat -apn|grep 'nginx: worker'|wc -l
).
[root@rakcdn ~]# netstat -apn|grep 'nginx: worker'|wc -l
1096
References:
Some content in this article is referenced from: NGINX: View Concurrent Connections
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.