nginx: Too many open files

Created:

2016-11-16 13:07:45 UTC

Modified:

2017-08-17 15:19:39 UTC

6

Was this article helpful?


Have more questions?

Submit a request

nginx: Too many open files

Applicable to:

  • Plesk for Linux

Symptoms

  • When nginx support is enabled and there are a lot of domains (more than 256), nginx will fail with the following error:

    2012-11-08T20:13:34+07:00 ERR (3): Apache config (13523804010.47553900) generation failed: nginx: [emerg] open() "/var/www/vhosts/test255.tld/statistics/logs/proxy_access_ssl_log" failed (24: Too many open files)
    nginx: configuration file /etc/nginx/nginx.conf test failed
  • Incorrect SSL certificate is assigned to the domain.

  • SSL certificate is not updated: after SSL certificate is changed in Plesk old certificate is shown in a web-browser.

Cause

Nginx's virtual host opens 4 log files for each virtual host with physical hosting:

  1. proxy_access_log
  2. proxy_access_ssl_log
  3. webmail_access_log
  4. webmail_access_ssl_log

As a result of this fact, the maximum number of open files is exceeded by nginx server.

Resolution

  1. Set the required ULIMIT value in the nginx configuration:

    For Debian-based:

    # echo 'NGINX_ULIMIT="-n 4096"' >> /etc/default/nginx

    For RHEL-based:

    # echo 'NGINX_ULIMIT="-n 4096"' >> /etc/sysconfig/nginx
  2. Set worker_rlimit_nofile value in the nginx configuration to increase the maximum number of opened files allowed by the worker process:

    # grep "worker_rlimit_nofile" /etc/nginx/nginx.conf 
    worker_rlimit_nofile 16384;
  3. For systems using systemd instead of SysV and LSB, LimitNOFILE should be increased in [Service] section. To do so, modify /usr/lib/systemd/system/nginx.service file:
    [Service]
    LimitNOFILE=4096

    Kindly note that systemd daemon should be reloaded after any changes in the unit configuration files:

    # systemctl --system daemon-reload
  4. Restart nginx service:

    # service nginx restart
  5. Regenerate the web server configuration:

    # /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
Have more questions? Submit a request
Please sign in to leave a comment.