Nginx prompt: Too program open files solution

Source: Internet
Author: User

If nginx error. log contains a large number of Too Upload open files, it indicates that the file handle is not enough. In this case, we need to increase the number of file handles in the system and the maximum number of connections allowed by nginx.

By default, the maximum number of files that can be opened in a linux file system is 1024. For a server used in a production environment, this setting is too low, for example, using nginx as a web server, when the concurrency reaches a certain number, you can see the error. log contains a large number of "Nginx accept () failed (24: Too open files)" errors. There are two solutions to this problem:

Method 1: use ulimit-n 655350 to set the maximum number of opened files to 655350. You also need to modify the nginx configuration file and set worker_rlimit_nofile to the same value.

1. Change the system file handle

The code is as follows: Copy code
Vi/etc/security/limits. conf

Add the following content:

The code is as follows: Copy code

Root soft nofile 10240
Root hard nofile 10240
Nobody soft nofile 10240
Nobody hard nofile 10240

Generally, we only need to increase the number of file handles for the root user and the nginx running user nobody. If you need to increase this value for each user, you can add the following content:

The code is as follows: Copy code

* Soft nofile 10240
* Hard nofile 10240


Note: modifying the file opening limit through ulimit only affects the current shell environment. Therefore, this is a temporary solution. The ultimate solution is Method 2.

Method 2: Add the following information to the/etc/security/limits. conf file:

The code is as follows: Copy code

* Soft nofile 655360
* Hard nofile 655360


2. Change the nginx. conf parameter.

The code is as follows: Copy code

Vi/etc/nginx. conf

Find the worker_rlimit_nofile and worker_connections parameters and change the value:

The code is as follows: Copy code

Worker_rlimit_nofile 10240;

Worker_connections 10240;

3. Restart nginx

Nginx-s reload
In this way, the new maximum number of allowed connections takes effect.

4. Check error. log to see if there is any Too program open files information. If there are still a large number of such errors, continue to increase the number of file handles according to the above steps.


Note: After this method is modified, you must restart the machine to make it take effect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.