: This article mainly introduces nginx Reverse proxy optimization (file descriptor). For more information about PHP tutorials, see. Lsof tool
A file descriptor is a simple integer used to indicate the files and sockets opened by each process. The first open file is 0, the second is 1, and so on. Linux usually imposes a limit on the number of files that can be opened by each process. Linux usually has a system-level 1024 limit.
As the concurrency increases, the default 1024 file descriptors of the original system will certainly be insufficient. the longer the time, the system may report the following error:
Open files limits .....
To view the file descriptor occupied by the nginx process, run the following command:
lsof | grep nginx
Partial results
nginx 6845 nobody 6u IPv4179045 0t0TCP *:http (LISTEN)nginx 6845 nobody 7u IPv4179046 0t0TCP *:ddi-tcp-1 (LISTEN)nginx 6845 nobody 8u unix 0xffff88005eda0c80 0t0179050 socketnginx 6845 nobody 9u REG0,903660 anon_inodenginx 6845 nobody 10u REG0,903660 anon_inode
* Note: The second line is the nginx process number.
# Count the number of files opened by the nginx process. run the following command lsof | grep nginx | wc-l.
Method 1:
The second column of the above result is the nginx process number.
cd /prec/6845
You can see the file generated by this process, and then read the limits file.
more limits
In row 8, Max open files is 51200 (the default value is 1024), because
I added a line to the top of nginx. conf:
worker_rlimit_nofile 51200;
Method 2:
Run:
ulimit -a
Run:
ulimit -SHn65535
You can.
Method 3:
[root@localhost6845]# sysctl -a | grep file-maxfs.file-max = 201604[root@localhost6845]#
Run:
[root@localhost6845]# sysctl -w fs.file-max=65535fs.file-max = 65535[root@localhost6845]# sysctl -a | grep file-maxfs.file-max = 65535
Edit to take effect permanently:
vim /etc/sysctl.conf
File, add the following line:
fs.file-max=65535
Then execute the following command to make it take effect:
sysctl -p