How to fix accept() failed (24: Too many open files) error in Nginx

Sometimes using LEMP on a web server you can come across 500 error. If you check on logs you can see something like:

[alert] 8668#0: accept() failed (24: Too many open files)

This indicates that the amount of files opened at the same time is off limit.

To fix it add to /etc/security/limits.conf:

* soft nofile 16384
* hard nofile 16384

Run as root:

ulimit -n 16384
Sudo will not work here.

It's also recommended to reboot the server, though it's not absolutely necessary.

In /etc/nginx/nginx.conf write:

worker_connections = 4096
worker_processes = 4

In case you didn't run ulimit -n 16384 command reboot the server.







Got a comment?

captcha =

Categories

  1. System (20)
    1. FreeBSD (5)
    2. Linux (9)
  2. Email (2)
  3. DNS (2)
  4. Databases (1)
  5. WebServer (27)
 
Copyright © 2012-2015 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.