nginx代理开启对http1.1的支持

话说nginx代理从1.1.4版本开始支持http1.1这无疑给后端被代理服务以静态文件为主的带来了福音。
大大降低了tcp开销,节省了系统资源当然也会降低time_wait连接数.
配置方法举例说明
   
   
   
   
  1. upstream nginx_test {
  2. server 192.168.128.128:8080 weight=5;
  3. server 192.168.128.132:8080 weight=5;
  4. keepalive 20;
  5. # 设置持久连接数,官方文档建议这个参数不用设置很大就足以够用了
  6. # nginx版本1.1.4以上支持这个指令
  7. }
  8.  
  9. server {
  10. location / {
  11. proxy_http_version 1.1;
  12. # 开启对http1.1支持
  13. proxy_set_header Connection "";
  14. # 设置Connection为空串,以禁止传递头部到后端
  15. # http1.0中默认值Connection: close
  16. proxy_pass http://nginx_test;
  17. }
  18. }
注意测试的时候可以观察netstat -ant|grep EST就会发现长连接生效了。
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive

你可能感兴趣的:(KeepAlive,HTTP1.1,nginx代理1.1)