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.

Share:
47,016

Related videos on Youtube

alfish
Author by

alfish

Updated on September 18, 2022

Comments

  • alfish
    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
    ravi yarlagadda over 12 years
    Sure - 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
    alfish over 12 years
    That'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
    ravi yarlagadda over 12 years
    Just 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
    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 almost keepalive_timeout*keepalive_requests