How to Fix “Too Many Open Files” Error in Nginx

Post Reply
User avatar
isscbta
Team Member
Posts: 147
Joined: Mon Jul 19, 2021 1:41 am
Has thanked: 18 times
Been thanked: 3 times

When hosting many websites on a myVesta server, Nginx may eventually hit the system-imposed limit on the number of simultaneously open files. This can cause the web server to fail with the following error message:

Code: Select all

[emerg] ... open() "... .error.log" failed (24: Too many open files)
This happens when the NOFILE (number of open files) limit is too low for the number of virtual hosts or log files being accessed.

Solution:

To raise the limit without overwriting existing configuration, first check if the override file already exists:

Code: Select all

if [ ! -f "/etc/systemd/system/nginx.service.d/limits.conf" ]; then
    mkdir -p /etc/systemd/system/nginx.service.d/
    echo "[Service]" > /etc/systemd/system/nginx.service.d/limits.conf
    echo "LimitNOFILE=65535" >> /etc/systemd/system/nginx.service.d/limits.conf
fi
If /etc/systemd/system/nginx.service.d/limits.conf already exists, edit it manually and add or adjust the LimitNOFILE value to at least 65535 or some value which suits you

Then apply the changes:

Code: Select all

systemctl daemon-reexec
systemctl daemon-reload
systemctl restart nginx

Tags:
Post Reply