brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx stub_status gives you a live connection count on one URL

Nginx
~/tips/tip-nginx-stub-status

location = /basic_status {

Shows how many connections nginx has open and what they are doing, on a small status page.

When a site feels slow, my first question is whether nginx is busy or bored. nginx has a tiny built-in status page for that, without any monitoring stack around it.

location = /basic_status {
    stub_status;
    allow 127.0.0.1;
    allow 192.168.1.0/24;
    deny all;
}

Put it in a server block, run nginx -t and reload. Then ask for it:

curl http://localhost/basic_status

You get a few lines of plain text, for example:

Active connections: 291
server accepts handled requests
 16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106

Active connections is everything open right now, including idle ones. Under it come the totals since start: accepted connections, handled connections and requests. If handled falls behind accepts, nginx is hitting a limit such as worker_connections. The last line splits the open connections into reading a request header, writing a response, and idle keep-alive ones waiting for their next request. A big Writing number on a slow site usually points at a slow backend or a slow client.

Because it is plain text, a monitoring tool can scrape it, and there are exporters for Prometheus that read exactly this page.

Two caveats. The module is not built by default, so check nginx -V for --with-http_stub_status_module first; the Ubuntu packages and the official Docker image have it. And keep the allow and deny lines: the counters are not secret, but there is no reason to show your traffic to the whole internet. On nginx older than 1.7.5 the directive needs an argument, stub_status on;.

Further reading: ngx_http_stub_status_module

Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link