nginx upstream开启keepalive
开启nginx和后端服务之间的keepalive能够减少频繁创建TCP连接造成的资源消耗
upstream tomcat {
server tomcat01.host:8080;
keepalive 1024;
}
server {
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://tomcat;
}
}
keepalive:
指定每个nginxworker可以保持的最大连接数量为1024,默认不设置,即nginx作为client时keepalive未生效
proxy_http_version 1.1:
开启keepalive要求HTTP协议版本为HTTP 1.1
proxy_set_header Connection "":
为了兼容老的协议以及防止http头中有Connection close导致的keepalive失效,这里需要及时清掉HTTP头部的Connection