Symptoms
-
The nginx service fails to start/reload with the following error in the
/var/log/nginx/error.log
file:nginx: [emerg] open() "/var/www/vhosts/system/example.com/logs/proxy_access_ssl_log" failed (24: Too many open files)
-
Some or all websites are not accessible
-
Warning is shown in the Tools & Settings > Diagnose & repair:
Checking for nginx ULIMIT value N domains have been found on server. Problem with nginx default limit for open files is possible
-
NodeJS and Ruby web applications are showing 502 Bad Gateway error when performing some Plesk tasks such as creating domains, subscriptions, changes on Apache or Nginx, etc:
Server Error
502 Bad Gateway
Web server received an invalid response while acting as a gateway or proxy server. -
After installing a new certificate for the domain, the old one is still shown in a web browser, however, the correct certificate is selected at the Domains > example.com > Hosting Settings page.
Cause
Nginx's virtual host opens 4 log files for each virtual host with physical hosting:
- proxy_access_log
- proxy_access_ssl_log
- webmail_access_log
- webmail_access_ssl_log
As a result of this fact, the maximum number of open files is exceeded by the nginx server due to a big number of domains (usually, more than 100).
Resolution
Warning: Execution of the websrv_ulimits
utility without --no-restart option initiates rebuilding of web configuration files for all domains and can cause significant downtime in case of a big number of hosted websites.
Execute the command during the maintenance time frame.
It is good practice to set open files limit value more than number of domains in Plesk * 16 at least. In example below provided actions how to set limit to 4096:
-
Connect to the server via SSH
-
Set open files limit to 4096 for both Apache and Nginx:
# /usr/local/psa/admin/sbin/websrv_ulimits --set 4096 --no-restart
-
Restart Apache and nginx services at Plesk > Tools & Settings > Services Management to apply changes.
-
Check that 'Max open files limit' was applied properly, after web services restarting:
# grep 'Max open files' /proc/$(cat /var/run/nginx.pid)/limits
Max open files 4096 4096 file -
If the solution above did not help, set the limit using the
ulimit
utility:# ulimit -n 4096