Nginx Reverse proxy optimization (file descriptor)

Source: Internet
Author: User
Tags nginx reverse proxy
: 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

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.