有个项目上的Keep-Alive配置一直不起作用,检查了很久代码找不到问题,然后灵光一现想到应该是反向代理配置的问题
即:client—–nginx proxy—–real server
client配置了使用keepalive,real server也支持,问题就在于nginx代理没配置对
配置方式如下:
配置upstream,keepalive需要在upstream里配置
12345upstream http_backend {server 127.0.0.1:8080;keepalive 16;}修改proxy设置,proxy_http_version必须设置为“1.1”,且需要清空Connection头
12345678910server {...location /http/ {proxy_pass http://http_backend;proxy_http_version 1.1;proxy_set_header Connection "";...}}
参考资料:http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive