nginx upstream turns on keepalive
upstream tomcat { server ops-coffee.cn:8080; keepalive 1024; } server { location / { proxy_http_version 1.1; proxy_set_header Connection ""; proxy_pass http://tomcat; } }
nginx will be used as a reverse proxy in most cases in the project, such as nginx followed by tomcat, nginx followed by php, etc. At this time, we enable keepalive between nginx and back-end services to reduce resource consumption caused by frequently creating TCP connections. The configuration is as above
keepalive: Specify the maximum number of connections that each nginxworker can maintain is 1024, which is not set by default. , that is, keepalive does not take effect when nginx is used as a client
proxy_http_version 1.1: Turning on keepalive requires the HTTP protocol version to be HTTP 1.1
proxy_set_header Connection "": In order to be compatible with old protocols and prevent Connection in the http header Keepalive failure caused by close requires timely clearing of the Connection
in the HTTP header.The above is the detailed content of How to enable keepalive in nginx upstream. For more information, please follow other related articles on the PHP Chinese website!