Keepalive connections
The keepalive
directive deserves special mention. NGINX will keep this number of connections per worker open to an upstream server. This connection cache is useful in situations where NGINX has to constantly maintain a certain number of open connections to an upstream server. If the upstream server speaks HTTP, NGINX can use the HTTP/1.1 persistent connections mechanism to maintain these open connections.
An example of such a configuration follows:
upstream apache { server 127.0.0.1:8080; keepalive 32; } location / { proxy_http_version 1.1; proxy_set_header Connection ""; proxy_pass http://apache; }
Here, we've indicated that we'd like to hold open 32 connections to Apache running on port 8080 of the localhost. NGINX need only negotiate the TCP handshake for the initial 32 connections per worker, and will then keep these connections open by not sending a Connection
header with the close token. With proxy_http_version
, we specify that we'd like to speak...