In one project, the Keep-Alive configuration never worked. After checking for a long time, the code could not be found. Then, Ling Guang thought that it should be a problem with reverse proxy configuration.
That is: client ----- nginx proxy ----- real server
Keepalive is configured for the client, and real server also supports it. The problem is that the nginx proxy is not configured
The configuration method is as follows:
1. Configure upstream and keepalive in upstream.
| The code is as follows: |
Copy code |
|
Upstream http_backend {
Server 127.0.0.1: 8080;
Keepalive 16;
} |
2. Modify the proxy settings. The proxy_http_version must be set to "1.1" and the Connection header must be cleared.
| The code is as follows: |
Copy code |
|
Server {
...
Location/http /{
Proxy_pass http: // http_backend;
Proxy_http_version 1.1;
Proxy_set_header Connection "";
...
}
} |