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?
Name (optional):
Anti-Bot:captcha =
Copyright © 2024 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.