How to adjust nginx keepalive_timeout?
47,016
What do you need to adjust it to do, or rather: are you seeing any problems with having it set how you do?
There isn't a good one-size-fits-all answer; if most client browsers are able to load all the resources on a page in 5 seconds then 5 seconds is just fine, but it completely depends on your application's needs - if your nginx server were serving as a reverse proxy for Exchange ActiveSync, for instance, you'd want it cranked all the way up to half an hour.
Related videos on Youtube
Author by
alfish
Updated on September 18, 2022Comments
-
alfish almost 2 years
I am using nginx along with php-fpm to server a busy mysql-based site. Currently I am using
keepalive_timeout = 5
, however I have no clear idea about how to optimally adjust it. So appreciate your hints. -
ravi yarlagadda over 12 yearsSure - so, pretty much "as low as possible without kicking most clients off before they load the page" - so if your pages load in under a second for most of your clients, then a 1 second timeout will be fine. But, unless your timeout is much, much higher than 5 seconds, then it's unlikely that it's a major cause of server load.
-
alfish over 12 yearsThat's the tricky point. How can I determine the page load time, given the difference in pages load time (some are heavier than others),visitor's connection speeds, etc.
-
ravi yarlagadda over 12 yearsJust ballpark it. A few seconds one way or another is unlikely to make any substantial difference in load, so feel free to estimate high - but then again, a new build of a TCP connection (even with an SSL handshake, if applicable) for a slow loading client isn't going to make a large difference in their overall loading speed.
-
Marki555 over 10 years@ShaneMadden, that 5 seconds are not the lifespan of the connection, but only a timeout during which server waits for another request up to
keepalive_requests
. So it is not important how much time it takes for the full page to load, just for the html until browser start fetching images/css... BTW the max. time connection is kept open is almostkeepalive_timeout*keepalive_requests