How to configure the maximum number of files open per process in Nginx

  • 2021-08-17 01:28:11
  • OfStack

1. View the maximum number of open files on the system

# View the current resource limit settings 
ulimit -a
core file size   (blocks, -c) 0
data seg size   (kbytes, -d) unlimited
scheduling priority    (-e) 0
file size    (blocks, -f) unlimited
pending signals     (-i) 7268
max locked memory  (kbytes, -l) 64
max memory size   (kbytes, -m) unlimited
open files      (-n) 1024
pipe size   (512 bytes, -p) 8
POSIX message queues  (bytes, -q) 819200
real-time priority    (-r) 0
stack size    (kbytes, -s) 8192
cpu time    (seconds, -t) unlimited
max user processes    (-u) 7268
virtual memory   (kbytes, -v) unlimited
file locks      (-x) unlimited

# View the maximum number of open files in the system 
ulimit -n
1024
2. Set the maximum number of open files in the system

# Permanently set the maximum number of open files in the system 
vi /etc/security/limits.conf
# Add parameters at the end 
......
* soft nofile 102400
* hard nofile 102400


# Temporarily set the maximum number of open files in the system 
ulimit -n 102400

# Test the operation, whether to permanently load the configuration after restarting 
# System restart 
init 6

# The test was successful, and the maximum number of open files was set correctly 
ulimit -n
102400
3. Set the maximum number of nginx open files

vi /usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 102400;
......

# Check nginx Is there a problem with the configuration 
nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

# Reload nginx
nginx -s reload

The maximum number of open files in the system and the maximum number of open files in nginx should be 1 as much as possible

Summarize


Related articles: