zlingh

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

一:设置

keepalive_timeout  0;

发curl:

[xxx ~]$ curl -H "Keep-Alive: 60" -H "Connection: keep-alive" '10.195.100.22:015/a.php'

tcpdump:

[xxx~]# tcpdump -i eth1 -n host 10.195.100.22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
20:04:54.008723 IP 10.46.43.13.47098 > 10.195.100.22.8015: Flags [S], seq 1443479700, win 14600, options [mss 1460,sackOK,TS val 3506368317 ecr 0,nop,wscale 8], length 0
20:04:54.040827 IP 10.195.100.22.8015 > 10.46.43.13.47098: Flags [S.], seq 3683863164, ack 1443479701, win 14480, options [mss 1460,sackOK,TS val 1561871560 ecr 3506368317,nop,wscale 8], length 0
20:04:54.040846 IP 10.46.43.13.47098 > 10.195.100.22.8015: Flags [.], ack 1, win 58, options [nop,nop,TS val 3506368349 ecr 1561871560], length 0
20:04:54.040909 IP 10.46.43.13.47098 > 10.195.100.22.8015: Flags [P.], seq 1:228, ack 1, win 58, options [nop,nop,TS val 3506368349 ecr 1561871560], length 227
20:04:54.073615 IP 10.195.100.22.8015 > 10.46.43.13.47098: Flags [.], ack 228, win 61, options [nop,nop,TS val 1561871593 ecr 3506368349], length 0
20:04:54.075765 IP 10.195.100.22.8015 > 10.46.43.13.47098: Flags [P.], seq 1:411, ack 228, win 61, options [nop,nop,TS val 1561871595 ecr 3506368349], length 410
20:04:54.075775 IP 10.46.43.13.47098 > 10.195.100.22.8015: Flags [.], ack 411, win 62, options [nop,nop,TS val 3506368384 ecr 1561871595], length 0
20:04:54.075812 IP 10.195.100.22.8015 > 10.46.43.13.47098: Flags [F.], seq 411, ack 228, win 61, options [nop,nop,TS val 1561871595 ecr 3506368349], length 0
20:04:54.075818 IP 10.46.43.13.47098 > 10.195.100.22.8015: Flags [.], ack 412, win 62, options [nop,nop,TS val 3506368384 ecr 1561871595], length 0
20:04:54.075871 IP 10.46.43.13.47098 > 10.195.100.22.8015: Flags [F.], seq 228, ack 412, win 62, options [nop,nop,TS val 3506368384 ecr 1561871595], length 0
20:04:54.108547 IP 10.195.100.22.8015 > 10.46.43.13.47098: Flags [.], ack 229, win 61, options [nop,nop,TS val 1561871628 ecr 3506368384], length 0

发现服务端主动断开了连接

使用nc和telnet

[xxx ~]$ nc 10.195.100.22 8015
GET /a.php HTTP/1.1
host:client.map.baidu.com
Connection: keep-alive
Keep-Alive: 5

HTTP/1.1 200 OK
Date: Sun, 19 Jul 2015 12:06:59 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Set-Cookie: BAIDUID=1556C9779F393DA51F0AF097670ADB40:FG=1; expires=Mon, 18-Jul-16 12:06:59 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode: 04194879830375702282071920
Server: Apache

1
a
0

[xxx ~]$ telnet 10.195.100.22 8015                                            
Trying 10.195.100.22...
Connected to xxx (10.195.100.22).
Escape character is '^]'.
GET /a.php HTTP/1.1
host:client.map.baidu.com
Connection: keep-alive
Keep-Alive: 5

HTTP/1.1 200 OK
Date: Sun, 19 Jul 2015 12:07:23 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Set-Cookie: BAIDUID=51ACA99FB5239F18891DAD65A018F0BF:FG=1; expires=Mon, 18-Jul-16 12:07:23 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode: 04434017180375702282071920
Server: Apache

1
a
0

Connection closed by foreign host.

tcpdump:

[xxx ~]# tcpdump -i eth1 -n host 10.195.100.22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
20:06:50.516727 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [S], seq 2242051012, win 14600, options [mss 1460,sackOK,TS val 3506484825 ecr 0,nop,wscale 8], length 0
20:06:50.552093 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [S.], seq 1023188555, ack 2242051013, win 14480, options [mss 1460,sackOK,TS val 1561988075 ecr 3506484825,nop,wscale 8], length 0
20:06:50.552107 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [.], ack 1, win 58, options [nop,nop,TS val 3506484860 ecr 1561988075], length 0
20:06:57.006536 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [P.], seq 1:21, ack 1, win 58, options [nop,nop,TS val 3506491315 ecr 1561988075], length 20
20:06:57.042492 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [.], ack 21, win 57, options [nop,nop,TS val 1561994566 ecr 3506491315], length 0
20:06:57.042504 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [P.], seq 21:70, ack 1, win 58, options [nop,nop,TS val 3506491351 ecr 1561994566], length 49
20:06:57.080212 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [.], ack 70, win 57, options [nop,nop,TS val 1561994603 ecr 3506491351], length 0
20:06:59.032504 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [P.], seq 70:84, ack 1, win 58, options [nop,nop,TS val 3506493341 ecr 1561994603], length 14
20:06:59.067393 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [.], ack 84, win 57, options [nop,nop,TS val 1561996591 ecr 3506493341], length 0
20:06:59.459524 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [P.], seq 84:85, ack 1, win 58, options [nop,nop,TS val 3506493768 ecr 1561996591], length 1
20:06:59.493148 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [.], ack 85, win 57, options [nop,nop,TS val 1561997017 ecr 3506493768], length 0
20:06:59.494975 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [P.], seq 1:411, ack 85, win 57, options [nop,nop,TS val 1561997018 ecr 3506493768], length 410
20:06:59.494982 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [.], ack 411, win 62, options [nop,nop,TS val 3506493803 ecr 1561997018], length 0
20:06:59.494985 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [F.], seq 411, ack 85, win 57, options [nop,nop,TS val 1561997018 ecr 3506493768], length 0
20:06:59.494990 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [.], ack 412, win 62, options [nop,nop,TS val 3506493803 ecr 1561997018], length 0
20:06:59.495012 IP 10.46.43.13.47686 > 10.195.100.22.8015: Flags [F.], seq 85, ack 412, win 62, options [nop,nop,TS val 3506493803 ecr 1561997018], length 0
20:06:59.528472 IP 10.195.100.22.8015 > 10.46.43.13.47686: Flags [.], ack 86, win 57, options [nop,nop,TS val 1561997052 ecr 3506493803], length 0

还是服务端主动断开了连接

 

二:设置

keepalive_timeout  60;

重启nginx(reload无效)

发curl

tcpdump:

[xxx ~]# tcpdump -i eth1 -n host 10.195.100.22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
20:10:02.019610 IP 10.46.43.13.49012 > 10.195.100.22.8015: Flags [S], seq 3318501607, win 14600, options [mss 1460,sackOK,TS val 3506676328 ecr 0,nop,wscale 8], length 0
20:10:02.054175 IP 10.195.100.22.8015 > 10.46.43.13.49012: Flags [S.], seq 3841619944, ack 3318501608, win 14480, options [mss 1460,sackOK,TS val 1562179576 ecr 3506676328,nop,wscale 8], length 0
20:10:02.054197 IP 10.46.43.13.49012 > 10.195.100.22.8015: Flags [.], ack 1, win 58, options [nop,nop,TS val 3506676362 ecr 1562179576], length 0
20:10:02.054249 IP 10.46.43.13.49012 > 10.195.100.22.8015: Flags [P.], seq 1:228, ack 1, win 58, options [nop,nop,TS val 3506676362 ecr 1562179576], length 227
20:10:02.088571 IP 10.195.100.22.8015 > 10.46.43.13.49012: Flags [.], ack 228, win 61, options [nop,nop,TS val 1562179611 ecr 3506676362], length 0
20:10:02.091411 IP 10.195.100.22.8015 > 10.46.43.13.49012: Flags [P.], seq 1:416, ack 228, win 61, options [nop,nop,TS val 1562179613 ecr 3506676362], length 415
20:10:02.091421 IP 10.46.43.13.49012 > 10.195.100.22.8015: Flags [.], ack 416, win 62, options [nop,nop,TS val 3506676399 ecr 1562179613], length 0
20:10:02.091544 IP 10.46.43.13.49012 > 10.195.100.22.8015: Flags [F.], seq 228, ack 416, win 62, options [nop,nop,TS val 3506676400 ecr 1562179613], length 0
20:10:02.126687 IP 10.195.100.22.8015 > 10.46.43.13.49012: Flags [.], ack 229, win 61, options [nop,nop,TS val 1562179648 ecr 3506676400], length 0
20:10:02.126703 IP 10.195.100.22.8015 > 10.46.43.13.49012: Flags [F.], seq 416, ack 229, win 61, options [nop,nop,TS val 1562179648 ecr 3506676400], length 0
20:10:02.126711 IP 10.46.43.13.49012 > 10.195.100.22.8015: Flags [.], ack 417, win 62, options [nop,nop,TS val 3506676435 ecr 1562179648], length 0

此时客户端断开了连接

 

nc或者telnet

[xxxx ~]$ telnet 10.195.100.22 8015                                            Trying 10.195.100.22...
Connected to xxx (10.195.100.22).
Escape character is '^]'.
GET /a.php HTTP/1.1
host:client.map.baidu.com
Connection: keep-alive
Keep-Alive: 5

HTTP/1.1 200 OK
Date: Sun, 19 Jul 2015 12:11:12 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: BAIDUID=C59340AAA043E8A90B1C04AE3695B17F:FG=1; expires=Mon, 18-Jul-16 12:11:12 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode: 06724697270375702282071920
Server: Apache

1
a
0

GET /a.php HTTP/1.1
host:client.map.baidu.com
Connection: keep-alive
Keep-Alive: 5

HTTP/1.1 200 OK
Date: Sun, 19 Jul 2015 12:11:19 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: BAIDUID=6CA0EEB34CC4FFEDDA20CA3893CF9E46:FG=1; expires=Mon, 18-Jul-16 12:11:19 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode: 06795641270375702282071920
Server: Apache

1
a
0

Connection closed by foreign host.

tcpdump

[xxxx ~]# tcpdump -i eth1 -n host 10.195.100.22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
20:11:04.742501 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [S], seq 196772776, win 14600, options [mss 1460,sackOK,TS val 3506739050 ecr 0,nop,wscale 8], length 0
20:11:04.777034 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [S.], seq 3344811817, ack 196772777, win 14480, options [mss 1460,sackOK,TS val 1562242305 ecr 3506739050,nop,wscale 8], length 0
20:11:04.777048 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [.], ack 1, win 58, options [nop,nop,TS val 3506739085 ecr 1562242305], length 0
20:11:10.873033 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 1:22, ack 1, win 58, options [nop,nop,TS val 3506745181 ecr 1562242305], length 21
20:11:10.907724 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 22, win 57, options [nop,nop,TS val 1562248436 ecr 3506745181], length 0
20:11:10.907735 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 22:73, ack 1, win 58, options [nop,nop,TS val 3506745216 ecr 1562248436], length 51
20:11:10.942783 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 73, win 57, options [nop,nop,TS val 1562248471 ecr 3506745216], length 0
20:11:11.681531 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 73:88, ack 1, win 58, options [nop,nop,TS val 3506745990 ecr 1562248471], length 15
20:11:11.717736 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 88, win 57, options [nop,nop,TS val 1562249244 ecr 3506745990], length 0
20:11:12.435530 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 88:90, ack 1, win 58, options [nop,nop,TS val 3506746744 ecr 1562249244], length 2
20:11:12.471209 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 90, win 57, options [nop,nop,TS val 1562249999 ecr 3506746744], length 0
20:11:12.472896 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [P.], seq 1:416, ack 90, win 57, options [nop,nop,TS val 1562250000 ecr 3506746744], length 415
20:11:12.472903 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [.], ack 416, win 62, options [nop,nop,TS val 3506746781 ecr 1562250000], length 0
20:11:18.466520 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 90:111, ack 416, win 62, options [nop,nop,TS val 3506752775 ecr 1562250000], length 21
20:11:18.501110 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 111, win 57, options [nop,nop,TS val 1562256030 ecr 3506752775], length 0
20:11:18.501127 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 111:162, ack 416, win 62, options [nop,nop,TS val 3506752809 ecr 1562256030], length 51
20:11:18.535716 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 162, win 57, options [nop,nop,TS val 1562256064 ecr 3506752809], length 0
20:11:19.046512 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 162:177, ack 416, win 62, options [nop,nop,TS val 3506753355 ecr 1562256064], length 15
20:11:19.081658 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 177, win 57, options [nop,nop,TS val 1562256610 ecr 3506753355], length 0
20:11:19.530550 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [P.], seq 177:179, ack 416, win 62, options [nop,nop,TS val 3506753839 ecr 1562256610], length 2
20:11:19.565884 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 179, win 57, options [nop,nop,TS val 1562257094 ecr 3506753839], length 0
20:11:19.568107 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [P.], seq 416:831, ack 179, win 57, options [nop,nop,TS val 1562257096 ecr 3506753839], length 415
20:11:19.568114 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [.], ack 831, win 66, options [nop,nop,TS val 3506753876 ecr 1562257096], length 0
20:11:29.582270 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [F.], seq 831, ack 179, win 57, options [nop,nop,TS val 1562267105 ecr 3506753876], length 0
20:11:29.582284 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [.], ack 832, win 66, options [nop,nop,TS val 3506763890 ecr 1562267105], length 0
20:11:29.582325 IP 10.46.43.13.49322 > 10.195.100.22.8015: Flags [F.], seq 179, ack 832, win 66, options [nop,nop,TS val 3506763890 ecr 1562267105], length 0
20:11:29.617689 IP 10.195.100.22.8015 > 10.46.43.13.49322: Flags [.], ack 180, win 57, options [nop,nop,TS val 1562267141 ecr 3506763890], length 0

此时:在发送完第一个http请求后,10内服务端并没有断开连接,客户端可以再次发生http包,并且可以复用上次的tcp连接,act和seq号都是接着之前的连接来的。10s如无请求才会断开。

另外:建立tcp连接后,如果客户端在60s内没有发送一个完整的htttp请求包,服务端也会断开此次tcp连接

posted on 2015-07-19 20:16  zlingh  阅读(1456)  评论(0编辑  收藏  举报