Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On TCP connections held by NGinx, can it be configured to send TCP Keepalive

(Not HTTP KeepAlive!)

share|improve this question

Made it:

share|improve this answer
does the existing listen option: so_keepalive not work? – chacham15 Dec 5 '14 at 9:29
As far as I see the so_keepalive is on per server basis since it is option to location directive. The module allows that configuration per location basis, that can be significant difference in some cases. – myroslav Dec 12 '14 at 9:57

Use the source, Luke.

(but why would you want to do such a thing?)

share|improve this answer
So our firewall would not disconnect long lived connections. – ripper234 Oct 22 '10 at 20:51
Why don't you just tell your firewall not to terminate long connections? – symcbean Oct 25 '10 at 8:03
Because there might be other firewalls along the way - I don't control them all. – ripper234 Dec 3 '10 at 6:36

At the moment, only mail proxy module supports "so_keepalive" directive.

share|improve this answer

There is as LD_PRELOAD module that turns keepalives on, even if the app doesn't have an option to do so. (I don't know if it works with nginx or not.)

share|improve this answer

You have 2 options:

  • use stock so_keepalive nginx option
  • use nginx-tcp-keepalive module directives

listen ... so_keepalive=on

listen directive with so_keepalive option is server level. See for full documentation. This option is available since 2011-12-12 in nginx 1.1.11 and later.


The nginx-tcp-keepalive module of Nicolas Viennot provides family of tcp_keep* directives that are location level. This module should work properly on modern Linux and BSD systems. Mac OS X support is limited to tcp_keepalive only. The module was originally releases approximately in the moment when nginx gained the so_keepalive option. I hadn't tried if the module is still compatible with newer version of nginx.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.