ScaleScaleScaleScale

Tips / Nginx


Nginx error: accept() failed (24: Too many open files)

accept() failed (24: Too many open files)

That was the error I noticed on Nginx logs last night:

[root@server.myserver.com:~]tail -f /etc/nginx/logs/error.log
2014/03/22 14:09:27 [crit] 18676#0: accept() failed (24: Too many open files)
2014/03/22 14:09:27 [crit] 18676#0: accept() failed (24: Too many open files)
2014/03/22 14:09:27 [crit] 18676#0: accept() failed (24: Too many open files)
2014/03/22 14:09:27 [crit] 18676#0: accept() failed (24: Too many open files)
2014/03/22 14:09:27 [crit] 18676#0: accept() failed (24: Too many open files)

This error was ocurring on a very busy website I manage. Nginx shows this error when it hits a user resource as well as open files limitation, Nginx reached the limit on the number of files it can open simultaneously. The solution is very easy and can be applied within 1 minute.

Follow this two steps:

1) Open Nginx configuration file (usually located at /etc/nginx/nginx.conf) set this variable after the worker_processes entry line:

worker_rlimit_nofile 100480;

2) Increase  open files limit at OS level:

Edit the file /etc/sysctl.conf, enter:

nano -w /etc/sysctl.conf

Add or modify the following variable to be:

fs.file-max = 120000

Apply the changes:

sysctl -p

Popular search terms:

  • https://www scalescale com/tips/nginx/nginx-accept-failed-24-too-many-open-files/#
  • nginx too many open files
  • https://www scalescale com/tips/nginx/nginx-accept-failed-24-too-many-open-files/
  • docker sock: accept4: too many open files
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking