What the message looks like
2026/10/29 14:02:11 [alert] 1234#1234: *98765 768 worker_connections are not enough while connecting to upstream, client: 203.0.113.5, server: example.com, request: "GET /api/ HTTP/2.0", upstream: "http://127.0.0.1:8080/api/"Common causes
worker_connectionsin theeventsblock is still the low value from the packagednginx.conf, and traffic has outgrown it.- A slow upstream keeps connections open for a long time, so they pile up (see also the 504 and 502 pages).
- Long-lived connections such as WebSocket, SSE or long polling occupy a slot for their whole lifetime.
- The limit is higher in nginx than the OS allows: the open-files limit of the nginx process is too small, so the value cannot be used.
- A flood of requests from bots or a misbehaving client.
Check
- Current worker settings
nginx -T 2>/dev/null | grep -nE 'worker_(processes|connections|rlimit_nofile)' - How often does the alert appear?
grep -c 'worker_connections are not enough' /var/log/nginx/error.log - Open-files limit of the running master process
grep 'open files' /proc/$(cat /run/nginx.pid)/limits - Socket summary (established vs. waiting)
ss -s
Fix
- Raise the limit in
/etc/nginx/nginx.conf:events { worker_connections 4096; }and keepworker_processes auto;. - Allow enough file descriptors:
worker_rlimit_nofile 8192;in the main context, at least twiceworker_connectionswhen proxying. - If systemd limits the service, add a drop-in with
systemctl edit nginxand setLimitNOFILE=to a matching value. - Reduce the load itself: fix the slow upstream, enable
keepaliveto the upstream, and limit abusive clients withlimit_req. - Apply it:
nginx -t && systemctl restart nginx(a reload does not change the process limit set by systemd).
Typical scenario
A chat application with WebSockets runs behind nginx as a reverse proxy. At peak time the log fills with "768 worker_connections are not enough" lines, and new users cannot connect. 768 is the value from the packaged nginx.conf on Debian and Ubuntu. Every WebSocket connection occupies two slots, one to the browser and one to the backend. First enable stub_status and read "Active connections" at peak time.
FAQ
What is the maximum number of clients nginx can serve?
Roughly worker_processes × worker_connections, divided by two when nginx proxies every request, because each proxied request uses a client and an upstream connection.
Is a higher value always better?
No. Each connection needs memory and a file descriptor. Raise it moderately, make sure the file descriptor limit matches, and fix the cause if connections pile up because of a slow backend.
How do I see the current number of connections?
Enable the stub_status module in a location reachable only locally. Its output shows "Active connections" plus Reading, Writing and Waiting. Alternatively ss -s shows the open TCP connections of the whole server.
How many users does 768 connections mean with WebSockets?
About half, because each WebSocket keeps two connections open for its whole lifetime: one to the client and one to the upstream. Around 380 simultaneous chat users already use up a whole worker. More workers spread the load, but the limit applies per worker.
How can I tell whether the file limit really applies?
Read cat /proc/$(pgrep -o nginx)/limits and look at "Max open files". If it is lower than worker_connections times two, worker_rlimit_nofile or LimitNOFILE was not applied, and a higher value in events will not help.