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

What about the Nginx connection timeout? process management optimization helps you solve the problem.

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

Share

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

The following brings you Nginx connection timeout how to do, process management optimization to help you resolve, hope to bring some help to everyone in practical application, load balancing involves more things, there are not many theories, there are many books online, today we use the accumulated experience in the industry to do an answer.

Connection timeout for Nginx

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.

Configure nginx [root@localhost ~] # yum install pcre-devel zlib-devel gcc gcc-c++-y # # installation environment package [root@localhost ~] # useradd-M-s / sbin/nologin nginx # # create a programmatic user [root@localhost] # mkdir / chen # # create a mount point [root@localhost ~] # mount.cifs / / 192.168.100.23/LNMP / chen # # mount Password for root@//192.168.100.23/LNMP: [root@localhost chen] # tar zxvf nginx-1.12.2.tar.gz-C / opt/ # # extract [root@localhost chen] # cd / opt/ [root@localhost opt] # lsnginx-1.12.2 rh [root@localhost opt] # cd nginx-1.12.2/ [root@localhost nginx-1.12.2] # lsauto CHANGES.ru configure html man srcCHANGES conf contrib LICENSE README./configure\ # # install nginx components -- prefix=/usr/local/nginx\-- user=nginx\-- group=nginx\-- with-http_stub_status_ module [root @ localhost nginx-1.12.2] # make & & make install # # compile [root@localhost nginx-1.12.2] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # # make a soft link so that the system can identify the owner of nginx command [root@localhost nginx-1.12.2] # nginx- t # # check syntax errors nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful write nginx script in system startup script to facilitate service manager to manage [root@localhost nginx-1.12.2] # cd / etc/init.d/ # # to system startup script [root@localhost init.d] # vim nginx # # write a nginx script # ! / bin/bash#chkconfig:-99 20 # comment message # description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" # this variable Point to my command file PIDF= "/ usr/local/nginx/logs/nginx.pid" # this variable, and point to the nginx process number case "$1" in start) $PROG ; stop) kill-s QUIT $(cat $PIDF);; restart) $0 stop $0 start;; reload) kill-s HUP $(cat $PIDF) *) echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit 0 [root@localhost init.d] # chmod + x nginx # # increase the authority of Nginx [root@localhost init.d] # chkconfig-- add nginx # # add nginx [root@localhost init.d] # service nginx start [root@localhost init. D] # netstat-ntap | grep nginx tcp 0 0 0.0.0.0 LISTEN 17544/nginx * LISTEN 17544/nginx: master [root@localhost init.d] # systemctl stop firewalld.service [root@localhost init.d] # setenforce 0 configure connection timeout modify nginx configuration file [root@localhost ~] # cd / usr/local/nginx/conf/ [root@localhost conf] # vim nginx .conf adds 31 keepalive_timeout 65 180 to the http protocol level area # # 65 is the CVM timeout, 180 is the client timeout 32 client_header_timeout 80, # # 80 is the header timeout 33 client_body_timeout 80 in the web page, and # # 80 is the timeout of the body in the web page [root@localhost conf] # service nginx stop [root@localhost conf] # service nginx startnginx process management optimization view process [root@localhost conf] # ps aux | grep nginxroot 51524 0.0 20544 600? Ss 20:05 0:00 nginx: master process / usr/local/nginx/sbin/nginxnginx 51525 0.0 0.0 23072 1388? S 20:05 0:00 nginx: worker processroot 51531 0.0 112728 972 pts/3 S + 20:06 0:00 grep-- color=auto nginx

Master only plays a supervisory role and will not process requests.

Worker is the working process, processing requests

We only have one working process here, and all requests will be handed over to it.

If we want to optimize, we have to extend, we extend directly in the virtual machine.

If our nginx is on Aliyun, which can be expanded manually or automatically, we need to write an automatic orchestration tool for automatic expansion. We need to trigger such as insufficient CPU, and we need zbbix monitoring at this time.

Cpu memory hard disk network bandwidth these are called vertical expansion

The number of server instances is called horizontal scaling

[root@localhost conf] # init 0 # # shut down the server to expand

Go back to the server and modify the configuration file [root@localhost ~] # cd / proc/ # # to view your cpu Memory Information [root@localhost proc] # ls1 1536 1790 305 40 526 626 devices mtrr10 1542 18 306 41 53 628 72 diskstats net100 1545 189 307 416 54 63 723 dma pagetypeinfo1082 1557 19 31 417 55 630 724 driver partitions1084 1562 2 319 418 558 651 73 execdomains sched_debug1085 1565 20 32 42 560 652,732 fb Schedstat1089 1581 21 320 43 575 654 733 filesystems scsi1096 1594 22 33 433 576 666 74 fs self11 16 23 333 44 577 667 75 interrupts slabinfo1106 1613 24 334 443 578 668 76 iomem softirqs1107 1629 25 335 45 579 669 763 ioports stat12 1633 26 336 450 580 671 77 irq swaps1228 1637 27 337 451 581 674 78 kallsyms Sys126 1640 28 338 456 582 675 79 kcore sysrq-trigger13 1648 288 339 47 583 679 8 keys sysvipc131 1651 289 34 48 584 685 80 key-users timer_list1335 1660 29 340 486 585 686 888 kmsg timer_stats1337 1668 290 341 49 586 687 9 kpagecount tty1338 1680 298 342 5 587 690 99 kpageflags uptime136 1687 299 343 50 588,697 acpi loadavg version14 1689 3 35 51 589 698 buddyinfo locks vmallocinfo1438 1696 30 36 516 590 7 bus mdstat vmstat1449 17 300 360 52 593 700 cgroups meminfo zoneinfo1478 1739 301 37 522 6 701 cmdline misc1479 1741 302 38 523 60 703 consoles modules15 1749 303 39 524 61 71 cpuinfo mounts1532 1768 304 525 62 716 crypto mpt [root@localhost proc] # cat cpuinfo # # View CPU There are 8 cores processor: 7vendor_id: GenuineIntelcpu family: 6model: 94model name: Intel (R) Core (TM) i7-6700HQ CPU @ 2.60GHzstepping: 3microcode: 0xcccpu MHz: 2591.567cache size: 6144 KBphysical id: 1siblings: 4core id: 3cpu cores: 4apicid: 7initial apicid: yesfpu_exception: yescpuid level: 22wp: yes modify nginx configuration file [root@localhost proc] # cd / Usr/local/nginx/conf/ [root@localhost conf] # vim nginx.conf 3 worker_processes 8 # # in the third line, there used to be only one core number. Now we change it to 8 cores to handle 1024 requests by default and allocate all requests to these 8 cores. Do load balancing 4 worker_cpu_affinity 01 10 [root@localhost conf] # service nginx stop [root@localhost conf] # service nginx start [root@localhost conf] # ps aux | grep nginx # # View process root 1951 0.0 20544 660? Ss 23:24 0:00 nginx: master process / usr/local/nginx/sbin/nginxnginx 1952 0.0 0.0 23072 1396? S 23:24 0:00 nginx: worker processnginx 1953 0.0 0.0 23072 1384? S 23:24 0:00 nginx: worker processnginx 1954 0.0 0.0 23072 1388? S 23:24 0:00 nginx: worker processnginx 1955 0.0 0.0 23072 1396? S 23:24 0:00 nginx: worker processnginx 1956 0.0 0.0 23072 1388? S 23:24 0:00 nginx: worker processnginx 1957 0.0 0.0 23072 1396? S 23:24 0:00 nginx: worker processnginx 1958 0.0 0.0 23072 1396? S 23:24 0:00 nginx: worker processnginx 1959 0.0 0.0 23072 1396? S 23:24 0:00 nginx: worker process

Root 1984 0.0 112728 972 pts/0 S + 23:25 0:00 grep-color=auto nginx

Read the above about Nginx connection timeout how to do, process management optimization to help you resolve, if there is anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineers to answer, technical engineers have more than ten years of experience in the industry.

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