Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

nginx: 512 worker_connections are not enough: find what fills the connection pool before raising the limit

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

An nginx error log line of the form 512 worker_connections are not enough means one worker process has used every connection slot it was configured with. The number at the start is the configured worker_connections value. Three forms exist, and they differ in severity: an alert when a connection could not be taken, a warning when nginx closed idle connections to make room, and an emergency at start-up when the setting is too small for the listening sockets alone.

What the error means

The nginx documentation for worker_connections gives the default as 512 and the context as events. It sets the maximum number of simultaneous connections for one worker process, and the page adds two points that decide most cases:

  • "this number includes all connections (e.g. connections with proxied servers, among others), not only connections with clients."
  • "the actual number of simultaneous connections cannot exceed the current limit on the maximum number of open files, which can be changed by worker_rlimit_nofile."

Reading ngx_get_connection and ngx_drain_connections in src/core/ngx_connection.c and ngx_event_init_conf in src/event/ngx_event.c (tag release-1.31.10), the code writes three forms:

Message in the source Level When it is written
N worker_connections are not enough alert A worker asks for a connection and none is free, after the reuse attempt below
N worker_connections are not enough, reusing connections warn Free connections are down to 1/16 of the pool or fewer and idle reusable connections exist; nginx closes some of them. The code writes it at most once per second
N worker_connections are not enough for M listening sockets emerg At start or reload, the setting is too small for the listening sockets; the configuration is rejected

The error_log documentation lists the levels in increasing severity (debug, info, notice, warn, error, crit, alert, emerg) and says the default level error logs "error, crit, alert, and emerg messages". So with a default configuration the alert form appears in the log but the warn form does not; the warn form needs warn or a lower level on error_log.

The ngx_http_stub_status_module page gives a second view of the same limit. Its handled counter is "Generally, the parameter value is the same as accepts unless some resource limits have been reached (for example, the worker_connections limit)." A handled figure below accepts therefore points at a limit like this one.

Idle client connections count against the pool. The keepalive_timeout default is 75 seconds, so a keep-alive client connection can stay open for that long between requests.

Likely causes

Cause What you see How to confirm
worker_connections too small for the load, including proxied connections The alert form at busy times; the default 512 in use Active connections near the limit during the log entries (stub_status, below)
Upstream servers answer slowly, so connections stay open longer The alert form together with upstream timeouts Timeouts in the error log; see nginx 504 Gateway Time-out: upstream timed out (110: Connection timed out) while reading response header
Many idle keep-alive client connections The warn form, with Waiting high in stub_status Waiting is a large part of Active connections
The open-file limit is below worker_connections Errors begin below the configured value /proc/PID/limits of a worker shows a lower open-files limit than worker_connections
Setting too small for the listening sockets The emerg form; nginx will not start or reload The message ends in for M listening sockets

Prove the cause before changing anything

All of these only read.

1. Which form, and how often?

grep -n 'worker_connections are not enough' /var/log/nginx/error.log

The path is an example; the error_log directive sets it. The text in the line tells you the form. The time stamps show whether it happens at one busy time or all day.

2. What is configured?

nginx -T > /root/nginx-config-dump.2026-12-01.txt
grep -n -E 'worker_connections|worker_processes|worker_rlimit_nofile|keepalive_timeout' /root/nginx-config-dump.2026-12-01.txt

The command-line page says -T is the same as -t but "additionally dump configuration files to standard output". In src/core/nginx.c (tag release-1.31.10) the dump comes after the configuration was accepted, so when the configuration is rejected, as with the emergency form above, nginx -T prints no dump; read the configuration files directly with grep -Rn on the directory that holds them. If a directive does not appear, its default applies: worker_connections 512, worker_processes 1 and no worker_rlimit_nofile.

3. What do the workers' limits say?

pgrep -a nginx
cat /proc/PID/limits

The pgrep manual says -a lists "the full command line as well as the process ID". Replace PID with a worker process ID from that list. The proc_pid_limits manual says the file "displays the soft limit, hard limit, and units of measurement for each of the process's resource limits". Read the line for open files. A good result is a soft limit higher than worker_connections.

4. How many connections are active at the busy time?

If a stub_status location is already configured, request it. The module is "not built by default"; its documented example is location = /basic_status { stub_status; }:

curl -s http://127.0.0.1/basic_status

The page shows Active connections, the accepts handled requests counters, and Reading, Writing and Waiting. Active connections is "The current number of active client connections including Waiting connections", and Waiting is "idle client connections waiting for a request". The figure counts clients only, so a reverse proxy has more connections than it shows. Do not add a status location only for this check without a plan to remove it; adding one is a configuration change.

Fix

The documented levers are the setting itself and the open-file limit. The step below raises both and leaves the cause analysis to you: if upstream servers are slow, a larger pool only moves the point at which it fills.

First save the current file. The example uses the main file; use the file that holds your events block:

cp -p /etc/nginx/nginx.conf /etc/nginx/nginx.conf.2026-12-01

Disruptive step: the next edit raises the number of connections each worker may hold and the open-file limit for the workers, and the reload that follows starts new worker processes. More connections per worker means more memory and descriptors in use at peak; the nginx documentation gives no figure for that cost. If the test fails, nothing is reloaded.

Edit the file saved above. worker_rlimit_nofile goes at the top level (context main) and worker_connections inside events. The values are our example values. The documentation says the number of connections cannot exceed the open-files limit, so the first value is chosen at least as large as the second:

worker_rlimit_nofile 4096;

events {
    worker_connections 2048;
}

Keep any other lines already in those blocks. Then test, and reload only if the test reports no error:

nginx -t
nginx -s reload

The Beginner's Guide says that if the reload is a success the master process starts new workers and asks the old ones to shut down, and "Otherwise, the master process rolls back the changes and continues to work with the old configuration."

To undo it: restore the saved file, test, and reload.

ls -l /etc/nginx/nginx.conf.2026-12-01 && cp -p /etc/nginx/nginx.conf.2026-12-01 /etc/nginx/nginx.conf
nginx -t
nginx -s reload

If the open-file limit set by the service manager is lower than worker_rlimit_nofile, see “Too many open files” on a Linux service: raise LimitNOFILE the right way. If many idle keep-alive connections are the cause, the keepalive_timeout directive (default 75s) controls how long they stay; lowering it is a separate decision for the client experience.

Example (illustrative): web01 runs nginx as a reverse proxy with worker_processes 2 and no worker_connections, so the default of 512 applies per worker. At the busy time, Active connections is 700 with Waiting 100, so about 600 connections are reading or writing. If each of those also holds one upstream connection, the total is 700 + 600 = 1,300. Each worker's limit is 512, so two workers can hold at most 2 x 512 = 1,024. The alert form appears. After the change above, the per-worker limit is 2,048 and the open-file limit is 4,096, so the same load fits with room, and handled stays equal to accepts.

Confirm the fix

  1. nginx -t reported no error and the reload ran.
  2. cat /proc/PID/limits for a new worker shows an open-files soft limit of at least the figure you set.
  3. No new worker_connections are not enough lines appear during the next busy period.
  4. In stub_status, handled equals accepts, as the module page describes for a server that is not at a resource limit.

What to watch afterwards

  • Active connections at the busiest hour, against the limit. Check again after traffic grows or an upstream gets slower.
  • Upstream response times. A rising time with rising connections points at the upstream, not at nginx.
  • Memory use of the workers after the change, since the nginx documentation gives no per-connection figure.
  • The error_log level: leave it at error or lower in normal use so the alert form is visible.

Risks and limits

  • These commands have not been run or lab-tested.
  • The message forms and their levels are a reading of the nginx source at tag release-1.31.10; a packaged build may differ slightly.
  • The nginx documentation states the per-worker limit and that it includes proxied connections. It gives no formula for the total across workers. The example multiplies the per-worker limit by the number of workers and assumes one upstream connection per request in progress; both are illustration, not documented rules.
  • worker_rlimit_nofile changes the limit for the workers; the nginx documentation does not describe the hard limit set by the operating system, which the /proc/PID/limits file shows.
  • The memory cost of a larger pool is not documented in the nginx documentation.

Sources