If there are more than 256 domains, Nginx fails with a "Too many open files" error

Refers to:

  • Plesk 12.5 for Linux
  • Plesk 11.0 for Linux
  • Plesk 11.5 for Linux
  • Plesk 12.0 for Linux
  • Plesk 10.3 for Linux

Created:

2016-11-16 13:07:45 UTC

Modified:

2017-02-17 19:08:37 UTC

1

Was this article helpful?


Have more questions?

Submit a request

If there are more than 256 domains, Nginx fails with a "Too many open files" error

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.

Cause

The Nginx virtual host opens four 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 the Nginx server.

Resolution

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

    Debian/Ubuntu:

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

    RHEL/CentOS/openSUSE:

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

    # grep 16384 /etc/nginx/nginx.conf 
    worker_rlimit_nofile 16384;

    NOTE: For operating systems using ' systemd ' instead of SysV and LSB, for example: CentOS 7, RHEL 7, Debian 7

    Systemd's LimitNOFILE must be increased in the ' [Service] ' section. To do so, modify a file named /usr/lib/systemd/system/nginx.service

    [Service]
    LimitNOFILE=4096

    You have to reload the systemd daemon after you make any changes in unit configuration:

    # systemctl --system daemon-reload
  3. Restart the Nginx service:

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

    # /usr/local/psa/admin/sbin/httpdmng --reconfigure-all

Further steps are required for Parallels Plesk 11.0.9. only

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

    Debian/Ubuntu:

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

    RHEL/CentOS/openSUSE:

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

    # grep 16384 /etc/nginx/nginx.conf 
    worker_rlimit_nofile 16384;
  3. Download and apply the required patch by running the commands below. The first command creates a backup of the original file being patched and puts it into the /root directory:

    # cp /etc/init.d/nginx /root/nginx.backup

    Debian/Ubuntu:

    # wget http://kb.plesk.com/Attachments/22839/Attachments/nginx.debian-ubuntu.patch
    # patch /etc/init.d/nginx nginx.debian-ubuntu.patch

    RHEL/CentOS:

    # wget http://kb.plesk.com/Attachments/22839/Attachments/nginx.redhat-centos.patch
    # patch /etc/init.d/nginx nginx.redhat-centos.patch

    openSUSE:

    # wget http://kb.plesk.com/Attachments/22839/Attachments/nginx.suse.patch
    # patch /etc/init.d/nginx nginx.suse.patch
  4. Change the limit for open file descriptors for the root and psaadm users:

    # egrep "root|psaadm" /etc/security/limits.conf
    root hard nofile 4096
    root soft nofile 4096
    psaadm hard nofile 4096
    psaadm soft nofile 4096

Note: Terminal re-login is required for these changes to take effect.

  1. Add the line ulimit -n 32768 at the beginning of the /usr/local/psa/admin/sbin/nginx-config script:

    #!/usr/bin/env bash
    ulimit -n 32768
  2. Restart the sw-cp-server and Nginx services:

    # /etc/init.d/sw-cp-server restart
    # /etc/init.d/nginx restart
  3. Regenerate the web server configuration:

    # /usr/local/psa/admin/sbin/httpdmng --reconfigure-all

Note that these settings will NOT be overwritten during the installation of a microupdate.

Have more questions? Submit a request
Please sign in to leave a comment.