Nginx accept() failed (24: Too many open files) while accepting new connection

The error below is typical in a new Nginx installation for a busy web site. Nginx apparently hits a user resource as well as configuration limitation:

2010/10/30 19:33:23 [alert] 5554#0: accept() failed (24: Too many open files) while accepting new connection on 0.0.0.0:80

This means that Nginx reached an imposed limit (read: artificial) on the number of files it can open simultaneously. Without further delay, here’s how to fix this error.

The fix is simple and consists of two lines worth of changes. The first change needs to be done in the startup script of Nginx (/etc/init.d/nginx for example). Add the following line at the top right after the shell script interpreter location (shebang):

ulimit -n 65535

Then open the nginx configuration file (default: /etc/nginx/nginx.conf) and the following line right after the “worker_processes” entry line

worker_rlimit_nofile 20480;

Once both changes are made, run the Nginx lint to make sure no errors have been introduced:

# nginx -t
2010/11/01 17:07:46 [info] 9520#0: the configuration file /etc/nginx/nginx.conf syntax is ok
2010/11/01 17:07:46 [info] 9520#0: the configuration file /etc/nginx/nginx.conf was tested successfully
and then restart Nginx
/etc/init.d/nginx restart
That’s all folks! We hope this was useful.

Leave a Reply

Comment moderation is enabled. Your comment may take some time to appear.


Search The Blog







Categories