码迷,mamicode.com
首页 > 其他好文 > 详细

关于nginx keep-alive 参数的验证和心得

时间:2016-04-15 23:20:29      阅读:429      评论:0      收藏:0      [点我收藏+]

标签:浏览器   服务器   chrome   return   status   

用chrome连接nginx服务器(nginx+spero),发现每次请求结果返回给浏览器后,会过一会才会运行

ngx_http_close_connection函数,可以看到nginx返回给chrome的header和结果是:

HTTP/1.1 200 OK

Server: nginx

Date: Fri, 15 Apr 2016 08:39:50 GMT

Content-Type: text/plain

Content-Length: 28

Connection: keep-alive

Keep-Alive: timeout=5


spero return ads, status 200


而通过curl访问,也是返回同样的结果,但是nginx会立刻调用ngx_http_close_connection函数,看起来keep-alive没有起作用,猜测是curl拿到结果后立马主动关闭连接。

HTTP/1.1 200 OK

Server: nginx

Date: Fri, 15 Apr 2016 08:44:11 GMT

Content-Type: text/plain

Content-Length: 28

Connection: keep-alive

Keep-Alive: timeout=5


spero return ads, status 200



那么做一个实验:设置nginx的配置文件,将keep-alive关掉,看看chrome访问时是否ngx_http_close_connection函数立刻被调用?

首先,用命令:keepalive_timeout 0 禁用长连接,则看到header中的Connection为close

HTTP/1.1 200 OK

Server: nginx

Date: Fri, 15 Apr 2016 08:50:05 GMT

Content-Type: text/plain

Content-Length: 28

Connection: close


spero return ads, status 200


同时,在nginx print的log中也可以看到,ngx_http_finalize_request函数之后,ngx_http_close_connection函数立刻就被调用了。


在spero项目中,长连接必须被关闭以支持大并发请求。


关于nginx keep-alive 参数的验证和心得

标签:浏览器   服务器   chrome   return   status   

原文地址:http://1038741.blog.51cto.com/1028741/1764232

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!