Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx optimization-connection timeout and process management

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Configure Nginx to realize connection timeout

In the enterprise website, in order to avoid the same customer occupying the connection for a long time, resulting in a waste of resources, the corresponding connection timeout parameters can be set to control the connection access time.

Use the Fiddler tool to view connection parameters

The timeout parameter Keepalive_ timeout# sets the timeout of the connection. The default is 75 seconds. It can be set according to the situation of the website, or closed. You can set Client_header_ timeout# in the http segment, server segment, or location segment to specify the timeout period for waiting for the client to send the request header. Client_ body_ _ timeout# sets the request body reading timeout time to change the number of Nginx running processes.

1. In high concurrency scenarios, more Nginx processes need to be started to ensure fast response to process user requests and avoid blocking

two。 You can use the ps aux command to view the number of processes that Nginx is running

3. Change the configuration method for the number of processes: configuration file, modify process configuration parameters

4. Modify the worker_ _ processes parameter of the configuration file

(1) generally set to the number of CPU or kernels

(2) it can be set to 2 times the number of CPU or cores in the case of high concurrency.

5. If there are more running processes, Nginx will not temporarily start new processes to provide services in response to access requests, which reduces the overhead of the system and improves the service speed.

6. Use ps aux to view the changes in the number of running processes

7. By default, multiple processes in Nginx may run on one CPU, and different processes can be assigned to different CPU processing, making full use of hardware multi-core and multi-CPU.

8. On a 4-core physical server, processes can be assigned with the following configuration: Worker_ cpu affinity 0001 0010 0100 1000

Example demonstration 1. Nginx connection timeout demonstrates modifying the nginx.conf configuration file [root@localhost ~] # cd / usr/local/nginx/conf/ [root@localhost conf] # vim nginx.conf#keepalive_timeout 0keepalivetimeout 65 180; # the timeout of the server and client can be set in http\ server\ location; # the timeout waiting for the client to send the request header will send a 408 error client_body_timeout 80 # request body timeout [root@localhost conf] # systemctl stop nginx [root@localhost conf] # systemctl start nginx II. Nginx process management demonstration step 1: shut down the virtual machine and add CPU

Step 2: view the Nginx process information [root@localhost ~] # ps aux at this time | grep nginxroot 1854 0.0 20544? Ss 14:17 0:00 nginx: master process / usr/local/nginx/sbin/nginxnginx 1855 0.0 0.0 23072 1392? S 14:17 0:00 nginx: worker processroot 1859 0.0 112728 972 pts/0 S+ 14:18 0:00 grep-- color=auto nginx step 3: modify the configuration file [root@localhost ~] # cd / proc/ [root@localhost proc] # cat cpuinfo # # View the number of cpu cores processor: 0 # # first CPU...processor: 1 # # second CPU... [root@localhost proc ] # vim / usr/local/nginx/conf/nginx.conf#user nobody Worker_processes 2 to modify the same number of cores or 2 times worker_cpu_affinity 01 10 to set each process to have different CPU processing

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report