一:设置

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 bytes
::54.008723 IP 10.46.43.13. > 10.195.100.22.: Flags [S], seq , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::54.040827 IP 10.195.100.22. > 10.46.43.13.: Flags [S.], seq , ack , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::54.040846 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::54.040909 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::54.073615 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::54.075765 IP 10.195.100.22. > 10.46.43.13.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::54.075775 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::54.075812 IP 10.195.100.22. > 10.46.43.13.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::54.075818 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::54.075871 IP 10.46.43.13. > 10.195.100.22.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::54.108547 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length

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

使用nc和telnet

[xxx ~]$ nc 10.195.100.22
GET /a.php HTTP/1.1
host:client.map.baidu.com
Connection: keep-alive
Keep-Alive: HTTP/1.1 OK
Date: Sun, Jul :: GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Set-Cookie: BAIDUID=1556C9779F393DA51F0AF097670ADB40:FG=; expires=Mon, -Jul- :: GMT; max-age=; path=/; domain=.baidu.com; version=
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode:
Server: Apache a [xxx ~]$ telnet 10.195.100.22
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: HTTP/1.1 OK
Date: Sun, Jul :: GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Set-Cookie: BAIDUID=51ACA99FB5239F18891DAD65A018F0BF:FG=; expires=Mon, -Jul- :: GMT; max-age=; path=/; domain=.baidu.com; version=
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode:
Server: Apache a 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 bytes
::50.516727 IP 10.46.43.13. > 10.195.100.22.: Flags [S], seq , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::50.552093 IP 10.195.100.22. > 10.46.43.13.: Flags [S.], seq , ack , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::50.552107 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::57.006536 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::57.042492 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::57.042504 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::57.080212 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::59.032504 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::59.067393 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::59.459524 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::59.493148 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::59.494975 IP 10.195.100.22. > 10.46.43.13.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::59.494982 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::59.494985 IP 10.195.100.22. > 10.46.43.13.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::59.494990 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::59.495012 IP 10.46.43.13. > 10.195.100.22.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::59.528472 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length

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

二:设置

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 bytes
::02.019610 IP 10.46.43.13. > 10.195.100.22.: Flags [S], seq , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::02.054175 IP 10.195.100.22. > 10.46.43.13.: Flags [S.], seq , ack , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::02.054197 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::02.054249 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::02.088571 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::02.091411 IP 10.195.100.22. > 10.46.43.13.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::02.091421 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::02.091544 IP 10.46.43.13. > 10.195.100.22.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::02.126687 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::02.126703 IP 10.195.100.22. > 10.46.43.13.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::02.126711 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length

此时客户端断开了连接

nc或者telnet

[xxxx ~]$ telnet 10.195.100.22                                             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: HTTP/1.1 OK
Date: Sun, Jul :: GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: BAIDUID=C59340AAA043E8A90B1C04AE3695B17F:FG=; expires=Mon, -Jul- :: GMT; max-age=; path=/; domain=.baidu.com; version=
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode:
Server: Apache a GET /a.php HTTP/1.1
host:client.map.baidu.com
Connection: keep-alive
Keep-Alive: HTTP/1.1 OK
Date: Sun, Jul :: GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: BAIDUID=6CA0EEB34CC4FFEDDA20CA3893CF9E46:FG=; expires=Mon, -Jul- :: GMT; max-age=; path=/; domain=.baidu.com; version=
P3P: CP=" OTI DSP COR IVA OUR IND COM "
tracecode:
Server: Apache a 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 bytes
::04.742501 IP 10.46.43.13. > 10.195.100.22.: Flags [S], seq , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::04.777034 IP 10.195.100.22. > 10.46.43.13.: Flags [S.], seq , ack , win , options [mss ,sackOK,TS val ecr ,nop,wscale ], length
::04.777048 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::10.873033 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::10.907724 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::10.907735 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::10.942783 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::11.681531 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::11.717736 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::12.435530 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::12.471209 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::12.472896 IP 10.195.100.22. > 10.46.43.13.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::12.472903 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::18.466520 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::18.501110 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::18.501127 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::18.535716 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::19.046512 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::19.081658 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::19.530550 IP 10.46.43.13. > 10.195.100.22.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::19.565884 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::19.568107 IP 10.195.100.22. > 10.46.43.13.: Flags [P.], seq :, ack , win , options [nop,nop,TS val ecr ], length
::19.568114 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::29.582270 IP 10.195.100.22. > 10.46.43.13.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::29.582284 IP 10.46.43.13. > 10.195.100.22.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length
::29.582325 IP 10.46.43.13. > 10.195.100.22.: Flags [F.], seq , ack , win , options [nop,nop,TS val ecr ], length
::29.617689 IP 10.195.100.22. > 10.46.43.13.: Flags [.], ack , win , options [nop,nop,TS val ecr ], length

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

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

nginx之keepalive的更多相关文章

  1. 关于 Nginx upstream keepalive 的说明

    模块是 HttpUpstreamModule,配置的一个例子: [shell]upstream http_backend {    server 127.0.0.1:8080; keepalive 1 ...

  2. Nginx Upstream Keepalive 分析 保持长连接

    Nginx Upstream长连接由upstream模式下的keepalive指令控制,并指定可用于长连接的连接数,配置样例如下: upstream http_backend {     server ...

  3. 记一次线上由nginx upstream keepalive与http协议"协作"引起的接口报错率飙高事件

    年前接到个任务,说要解决线上一些手机客户端接口报错率很高的问题.拿到了监控邮件,粗略一看,各种50%+的错误率,简直触目惊心.这种疑难杂症解决起来还是挺好玩的,于是撸起袖子action. 最终的结果虽 ...

  4. Nginx http keepalive针对客户端行为指令

    keepalive 描述 多个http请求可以复用Tcp链接  减少握手次数 通过减少并发连接数减少服务器资源消耗 降低Tcp拥塞控制影响 Syntax: keepalive_disable none ...

  5. client,server,nginx 在使用keepAlive 专题

    2. TCP keepalive overview In order to understand what TCP keepalive (which we will just call keepali ...

  6. 我为什么要谈KeepAlive(文末增加nginx 负载tcp长连接保持 demo)

    http://blog.sina.com.cn/s/blog_e59371cc0102ux5w.html 最近工作中遇到一个问题,想把它记录下来,场景是这样的: 从上图可以看出,用户通过Client访 ...

  7. 转:nginx基础概念(keepalive、pipe)

    keapalive 当然,在nginx中,对于http1.0与http1.1也是支持长连接的.什么是长连接呢?我们知道,http请求是基于TCP协议之上的,那么,当客户端在发起请求前,需要先与服务端建 ...

  8. Nginx+keepalive 负载均衡

    1 规划和准备 两台相同配置的web 用途 IP MASTER 192.168.1.100 BACKUP 192.1681.101 2 安装 两台接入服务器分别安装NginX和keepalived: ...

  9. nginx keepalive 双机

    Nginx+keepalived双机热备(主从模式)   负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网 ...

随机推荐

  1. HTML格式与布局

    一.position:fixed 锁定位置(相对于浏览器的位置),例如有些网站的右下角的弹出窗口. <head> <title>123</title> <st ...

  2. HTML5 编辑 API 之 Range 对象(一)

     一.Range 对象基本概念 通过使用 Range 对象所提供的方法实现一个鼠标选取内容,通过点击按钮打印出选中内容,当然注意在不同的浏览器下可选中的内容数量是不同的. <!DOCTYPE h ...

  3. JAVA 静态代码块

    特点:随着类的加载而执行,并且只会执行一次,并且还优先于主函数.作用,用于给类进行初始化 /* 静态代码块 格式: static{ 静态代码块中的执行语句 } 特点:随着类的加载而执行,并且只会执行一 ...

  4. Java8之默认方法和静态接口方法

    前言 上一篇文章30分钟入门Java8之lambda表达式,我们学习了lambda表达式.现在继续Java8新语言特性的学习,今天,我们要学习的是默认方法和静态接口方法. 这一Java8的新语言特性, ...

  5. JS工作积累

    /* * YYYY-MM-DD类型的字符串日期比较 * */ String.prototype.compareAsDate=function(dateStr){//prototype原型方法 var ...

  6. 使用Aspose.Words把 word转成图片

    Document doc = new Document("f:\\333.doc"); ImageSaveOptions iso = new ImageSaveOptions(Sa ...

  7. Isilon OneFS Simulator Install Guide

    Isilon build for storage data Use VMware converter to convert node1 to ESX(参考silon_OneFS_Simulator_I ...

  8. Contains DuplicateII

    超时版: /*Contains Duplicate II Given an array of integers and an integer k, find out whether there the ...

  9. python3 AttributeError: 'NoneType' object has no attribute 'split'

    from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...

  10. .NET调用Java写的WebServices(可能会碰到的问题)

    1)net中定义的的WebService(返回值和参数都是自定义对象)可以被Java识别并调用,可是在Java中定义的WebService(返回值和参数都是自定义对象),C#客户端可以识别到自定义对象 ...