GrepBoard/Manuals
605 manuals ·

Fix nginx "(24: Too many open files)"

·Tested on nginx 1.30.6 (Docker nginx:stable) · 2026-10·Test scope ↓·6 steps

nginx "accept4() failed (24: Too many open files)" means a worker hit its open-file limit. Check Max open files, then raise it with worker_rlimit_nofile.

output
2026/10/30 22:38:39 [crit] 14#14: accept4() failed (24: Too many open files)

An nginx worker process has used up the number of files it may open (RLIMIT_NOFILE) and cannot accept new connections. Every connection takes one file descriptor, so when the limit is lower than worker_connections, concurrent connections stall at the limit. Check the worker's Max open files, then raise it with worker_rlimit_nofile. The call name in front can differ (socket(), open(), ...); if the trailing (24: …) is the same, so is the limit. Only accept4() was reproduced below.

[1] Read the worker's current limit. Use a worker PID, not the master's (ps -ef | grep 'nginx: worker'). Here PID 11 was the worker.

console
$ grep 'Max open files' /proc/11/limits
output
Max open files            64                   4096                 files     

The first number is the soft limit (the one in effect), the second the hard limit (the ceiling it can be raised to). The soft limit was lowered to 64 on purpose for this test. On a production host, 1024 is the common Linux default. If this number equals the open-file count in [3], the worker is at its limit.

[2] Treat the startup warning as a clue only. If worker_connections is larger than the limit, nginx warns when it starts. This config had worker_connections 1024;.

console
$ grep warn /var/log/nginx/error.log
output
2026/10/30 22:59:11 [warn] 10#10: 1024 worker_connections exceed open file resource limit: 64

The warning says the configured value is above the limit; it does not confirm the cause of the error you are seeing now. And no warning does not rule out a limit problem. When worker_rlimit_nofile is already set, the warning is not printed, yet the nginx source only logs [alert] setrlimit(RLIMIT_NOFILE, …) failed if applying that value fails and keeps running — with the low inherited limit, so (24: …) still appears. Decide from the real limit in [1] and the open-file count in [3], and look for setrlimit in the log too:

console
$ grep -n 'setrlimit' /var/log/nginx/error.log

[3] This is what hitting the limit looks like. With 100 connections held open, a new request was sent:

console
$ ls /proc/11/fd | wc -l
output
64
console
$ curl -s -m 3 http://127.0.0.1:8080/; echo "curl exit=$?"
output
curl exit=28

The worker's open descriptors stopped at the limit (64) and the new request got no answer within 3 seconds (exit code 28 = timeout). The log collects the same error. Remember this number; it is the baseline for checking later whether it grew.

console
$ grep -cE "crit.*Too many open files" /var/log/nginx/error.log
output
9

[4] Add worker_rlimit_nofile at the top of nginx.conf, outside events and http. Add one line; do not delete existing ones.

/etc/nginx/nginx.conf
worker_processes 1;worker_rlimit_nofile 2048; events {    worker_connections 1024;}

Set it **at or above worker_connections**, plus headroom for files that are not connections (logs, static files, cache). The official documentation says worker_connections already includes connections to proxied servers, so do not multiply by two just because it is a reverse proxy. The 2048 above is only an example with headroom over 1024. In this test, with 100 connections open the worker held 110 files (100 connections plus 10 of nginx's own). For counting connections see worker_connections tuning. The official nginx documentation describes this directive as a way to raise the limit "without restarting the main process".

console
$ nginx -t && nginx -s reload
output
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful

[5] After the reload, check the new worker. A reload starts new workers, and the old ones stay until their existing connections finish, then exit. So look at the new PID, not the one from [1], and test with fresh connections. Here the new worker was PID 44, and 100 new connections were opened.

console
$ grep 'Max open files' /proc/44/limits
output
Max open files            2048                 2048                 files     
console
$ ls /proc/44/fd | wc -l
output
110
console
$ curl -s -m 3 http://127.0.0.1:8080/; echo "curl exit=$?"
output
okcurl exit=0

The log was not cleared, so compare with the count from [3]. With no new errors it stays the same:

console
$ grep -cE "crit.*Too many open files" /var/log/nginx/error.log
output
9

Same 9 as in [3]: the old errors remain in the log and did not grow after the reload. The test ran in a container with a soft limit of 64 and a hard limit of 4096, so 2048 was within the hard limit and could be raised. An environment with a low hard limit was not tested.

[6] If nginx runs under systemd and the number does not go up, look at the service's limit. According to the systemd documentation, LimitNOFILE= sets the soft and hard limits together, or separately as soft:hard. The same page says the hard limit now defaults to 524288, a very high value, and that applications should raise their soft limit to the hard limit on their own. That is why worker_rlimit_nofile from [4] is usually enough, and the service limit only needs raising when the hard limit is pinned low.

Create a new drop-in file instead of editing the unit (--drop-in= sets the file name; the default is override.conf):

console
$ sudo systemctl edit --drop-in=nofile nginx

Put this in the editor that opens:

/etc/systemd/system/nginx.service.d/nofile.conf
[Service]LimitNOFILE=65536

Saving reloads the configuration. Processes that are already running keep the old limit, so restart and check the number again with the command from [1].

console
$ sudo systemctl restart nginx

Analyze your Nginx log in the browser ↗ — nothing is uploaded.

#nginx#too-many-open-files#worker_rlimit_nofile#worker_connections#LimitNOFILE