What exactly does keepalive_timeout work?

Aahan Krish krish at aahan.me
Sat Jun 18 11:04:09 UTC 2016

Hi Richard, thank you for your reply.

Since posting on this mailing-list I've come across some very good
(and credible) descriptions of Keep-Alive, and the best thing is that
they are all in agreement, i.e. no conflicting views. I'll quote them
here as a note to self and for everyone; they explain it all.

((1)) <https://tweaked.io/guide/general/webservers/>

""The purpose of keep-alive is simple in theory; rather than clients
having to open a fresh connection to your server for each request they
make (index, then CSS, then images), they open one connection.

When the initial connection is made that socket is kept open, rather
than beign closed, such that further requests can be using it.

>From the client point of view this improves things, as rather than
making the overhead to establish, use, and close, multiple connections
only one is used.

However the server is left keeping sockets open in the hope that
further requests will come, and if they don't resources are being
needlessly consumed which could be better spent on handling fresh

Generally people suggest leaving a small number of sockets available
for keep-alive, or only keeping sockets open for a short period of
time - such as five seconds - after which time the chances of a
further request are minimal.""

((2)) <https://support.microsoft.com/en-us/kb/813827>

""When Internet Explorer establishes a persistent HTTP connection with
a Web server (by using Connection: Keep-Alive headers), Internet
Explorer reuses the same TCP/IP socket that was used to receive the
initial request until the socket is idle for one minute. After the
connection is idle for one minute, Internet Explorer resets the
connection. A new TCP/IP socket is used to receive additional
requests. You may want to change the HTTP KeepAliveTimeout value in
Internet Explorer.

If either the client browser (Internet Explorer) or the Web server has
a lower KeepAlive value, it is the limiting factor. For example, if
the client has a two-minute timeout, and the Web server has a
one-minute timeout, the maximum timeout is one minute. Either the
client or the server can be the limiting factor.

By default, Internet Explorer has a KeepAliveTimeout value of one
minute and an additional limiting factor (ServerInfoTimeout) of two
minutes. Either setting can cause Internet Explorer to reset the

((3)) <http://kb.mozillazine.org/Network.http.keep-alive.timeout>

""Amount of time in seconds to keep keep-alive connections alive.
Default: 115 seconds.

Setting this to more than 115 probably won't help and will make things worse.""

NOTE: More on this in ((5)).

((4)) <http://kb.mozillazine.org/Network.http.max-persistent-connections-per-server>

On the maximum number of HTTP keep-alive connections the application
can have open at once to a single server: "Anything above 10 is

((5)) <https://blog.fastmail.com/2011/06/28/http-keep-alive-connection-timeouts/>

NOTE: That blog post is a must-read and also states when one would
want to have long HTTP keep-alive timeout on their server.

After following 4/5 links above, I have no questions on how the
`keepalive_timeout` directive works or what it's intended for. I'm

More information about the nginx mailing list