Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | Nginx |
Time | N/A |
- Number of all open connections.
- Stats about accepted connections.
- Connections per second and so on.
Configuration
Edit nginx.conf file:
# vi nginx.conf
Add or append the following in context location:
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; }
Save and close the file. Reload nginx server:
# service nginx reload
OR
# nginx -s reload
Test it
Open a web-browser and type the following url:
http://your-domain-name-here/nginx_status
OR
http://ip.address.here/nginx_status
Sample outputs:
- 586 = Number of all open connections
- 9582571 = Accepted connections
- 9582571 = Handled connections
- 21897888 = Handles requests
How do I calculate connections per seconds?
Requests per connection = handles requests / handled connections Requests per connection = 21897888/9582571 (pass this to bc -l using echo '21897888/9582571' | bc -l command) Requests per connection = 2.28
🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 7 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Very interesting tips !
Thank for that ;) I’ll test it soon
Have you tried logtop ?
logtop provide live statistics on a “tail -f any_log_file” :
For example, to get your top articles if your articles contains the pattern /article/ :
tail -f /var/log/*/access.log | grep –line-buffered /article/ | logtop
Or to get top IPs :
tail -f /var/log/*/access.log | cut -d’ ‘ -f1 | logtop
(You may prefer awk ‘{print $1; fflush();}’ if you have a very slow traffic cause cut is buffering)
logtop is in Debian testing and backports, or : https://github.com/JulienPalard/logtop
Works like a charm, thanks.
Any idea if it’s possible to Ajax / real-time this data?
Hi all,
I have done limited connections configuration to the nginx.
But i want ot know how to test the following configurations
For example i have limited one connection per ip in the nginx.
But if I opened 2 tabs from the browser and open the web even it is accessing
So i need to know how we can test the configurations for following
1). limited connections per ip
2). limited rate
3). and I have to access the particular files from the php file only, if we access directly it should not show
suppose any documents, audio and video files should not play directly, if i access through php file it should show.
I have attached my nginx.conf file png.
curl --silent http://127.0.0.1/nginx_status|sed '3q;d'|awk '{ print "echo " $3"/"$2"|bc -l" }'|sh
Thank you!
Is it possible to get the total connections made to every server block? I have nginx serving several domains, and I would like to know how many connections are made to every domain, not the total. Is it possible?