关于nginx keep-alive 参数的验证和心得
2016-04-15 16:53
676 查看
用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项目中,长连接必须被关闭以支持大并发请求。
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项目中,长连接必须被关闭以支持大并发请求。
相关文章推荐
- 小心服务器内存居高不下的元凶--WebAPI服务
- Android Manifest 用法
- Android学习笔记(二九):嵌入浏览器
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 运维入门
- 把Chrome OS安装在VMWare下及Chrome OS的关键特性和一些截图
- 回顾 Firefox 历史
- 小白观察:微软释放出其基于 Chromium 的 Edge 浏览器
- 利用开源软件打造自己的全功能远程工具
- Linux5.9无人值守安装
- 数据中心和云未来的十二大趋势
- 用vsftp快速搭建ftp服务器
- Linux快速构建apache web服务器
- 服务器监控策略浅谈
- 如何降低服务器采购成本 原理分析
- 建议的服务器分区办法
- 服务器托管六大优势分析