Troubleshooting guide
Nginx "worker_connections are not enough": how to fix it
A worker process hit its connection limit. A reverse proxy uses two connections for each client request, so the default fills up sooner than people expect.
3 min read10 sectionsUpdated
On this page
# How often has it occurred?
sudo grep -c 'worker_connections are not enough' /var/log/nginx/error.log
# Limits in use
sudo nginx -T 2>/dev/null | grep -E 'worker_processes|worker_connections|worker_rlimit_nofile'
# Active, reading, writing, waiting
curl -s http://127.0.0.1/nginx_status
# File descriptor limit of a running worker
cat /proc/$(pgrep -f 'nginx: worker' | head -1)/limits | grep 'open files'Fixes
Raise the limit, and raise descriptors with it:
worker_rlimit_nofile 65535; events { worker_connections 16384; }
Set worker_processes auto;. Enable keepalive to backends: keepalive 64; in the upstream, along with proxy_http_version 1.1; and an empty Connection header. Trim client_header_timeout and client_body_timeout to drop slow clients. Fix slow backends, since they are often the actual source of the pile-up. Reload with nginx -t && nginx -s reload, so that existing connections finish on the old workers.
What the status numbers mean
Active is all connections, including idle ones. Reading is connections sending their request, and a high number suggests slow clients. Writing covers requests being processed and responses being sent, and a high value suggests a slow backend or client download. Waiting is idle keep-alive connections, which are cheap and mostly harmless. A rise in Writing with traffic flat is a signature of backend slowness, and it is the reason a connection limit error can really be a database problem one layer away.
Catch it automatically
Alert when active connections exceed about 80 percent of capacity. Nginx monitoring charts those states over time, and performance tuning goes deeper.
What should worker_connections be?
Several thousand or more is common. Remember descriptors must match.
Why does it count double?
Each proxied request has a client connection and an upstream connection.
Does keepalive use more connections?
It holds a few idle ones but saves creating new ones.
Related reading
- PostgreSQL "too many clients already": how to fix it: Fix PostgreSQL FATAL: sorry, too many clients already. See who holds connections, stop leaks, add PgBouncer and size max_connections the right way.
- MySQL: Too many connections: Fix MySQL error 1040 Too many connections: check max_connections and current threads, find sleeping or leaked connections, size application pools.
- Too many TIME_WAIT connections: what to do: Understand Linux TIME_WAIT sockets, when they cause ephemeral port exhaustion, why keep-alive is the real fix and which kernel settings not to touch.
- ERR_TOO_MANY_REDIRECTS: how to fix a redirect loop: Fix ERR_TOO_MANY_REDIRECTS: trace the chain with curl, find the loop between CDN, server and app, such as HTTPS or www rules, and prevent it.
- 429 Too Many Requests: what it means and how to fix it: 429 Too Many Requests explained: rate limits, the Retry-After header, backoff with jitter for clients, and how to set fair rate limits on your own API.
- 501 Not Implemented: how to fix it: Fix 501 Not Implemented: unsupported HTTP methods, servers and proxies that do not support PATCH or WebDAV, and how it differs from 405 and 500.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.