Nginx worker_rlimit_nofile

How to set worker_rlimit_nofile to a larger number and what maximum value can it be or is it recommended?

I try to follow the following advice:

The second biggest limitation that most people are also dealing with is your OS. Open a shell, su for nginx user works like and then run ulimit -a command. These values ​​are all nginx restrictions cannot exceed. On many systems, the default value of open files is quite limited, on the system I just checked, it was set to 1024. If nginx works in a situation where it reaches this limit, it will log error (24: Too many open files) and return an error to the client. Naturally, nginx can process a lot more than 1024 files, and there is a chance that your OS can. You can safely increase this value.

To do this, you can set the limit using ulimit or use worker_rlimit_nofile to determine the desired open file descriptor limit.

From: https://blog.martinfjordvald.com/2011/04/optimizing-nginx-for-high-traffic-loads/

+7
source share
3 answers

worker_rlimit_nofile = worker_connections * worker_processes

+10
source

worker_rlimit_nofile = worker_connections * 2

because each connection opens two FDs, one for the client and one for the proxy server.

+2
source

When setting up the worker_rlimit_nofile parameter worker_rlimit_nofile you must consider both worker_connections and worker_processes . You can first check the OS file descriptor using: ulimit -Hn and ulimit -Sn , which will give you hard and software restrictions for each user, respectively. You can change the OS restriction using systemctl:

 sudo systemctl -w fs.file-max=$VAL 

where $ VAL is the number you want to set. However, if you automate the configuration, it is easy to set it up as follows:

 worker_rlimit_nofile = (worker_connections * worker_processes)*2 

Workflow is set to 1 by default, but you can set it to a number less than or equal to the number of cores available on your server:

 grep -c ^processor /proc/cpuinfo 
0
source

All Articles