Home > Operation and Maintenance > Nginx > How to enable keepalive in nginx upstream

How to enable keepalive in nginx upstream

WBOY
Release: 2023-05-14 19:04:17
forward
1479 people have browsed it

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;
 }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template