Giter Club home page Giter Club logo

nginx-tcp-keepalive's Introduction

Nginx TCP keepalive module

When using Nginx as a reverse proxy where the connections stay open (for example, to implement a server push), a problem arise when the client times out: nginx doesn't detect it because it doesn't use the TCP keepalive mechanism. The fact that nginx doesn't detect connection timeouts implies that the backend server (used for comet, server push, etc..) will see the client as connected forever which is bad for two reasons: 1) the client presence can matter in your application, and 2) resources will never get freed up.

Note: this has nothing to do with HTTP keepalive.

This module allows you to set the TCP keepalive values on http connections, namely TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL.

Installation

From source

Configure the Nginx sources with:

./configure --add-module=path/to/nginx_tcp_keepalive

And then compile/install with make/make install.

Configuration Options

tcp_keepalive

  • syntax: tcp_keepalive on|off
  • default: off
  • context: http, server, location

Enables the TCP keepalive mechanism.


tcp_keepcnt

  • syntax: tcp_keepcnt num
  • default: 2
  • context: http, server, location

The maximum number of keepalive probes TCP should send before dropping the connection.


tcp_keepidle

  • syntax: tcp_keepidle time
  • default: 1m
  • context: http, server, location

The time the connection needs to remain idle before TCP starts sending keepalive probes.


tcp_keepintvl

  • syntax: tcp_keepintvl time
  • default: 1m
  • context: http, server, location

The time between individual keepalive probes.

License

nginx_tcp_keepalive is distributed under the MIT license.

nginx-tcp-keepalive's People

Contributors

nviennot avatar quanah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nginx-tcp-keepalive's Issues

Fix Keepalive module for OSX

This module as written will not work on OSX. The following patch fixes this issue, as well as fixes the incorrect usage of SOL_TCP instead of IPPROTO_TCP.

--- nviennot-nginx-tcp-keepalive/ngx_http_tcp_keepalive_module.c.orig 2011-12-14 08:45:35.000000000 -0800
+++ nviennot-nginx-tcp-keepalive/ngx_http_tcp_keepalive_module.c 2012-06-25 12:34:45.000000000 -0700
@@ -36,9 +36,13 @@
}
})
SSO(SOL_SOCKET, SO_KEEPALIVE, conf->enable);

  •   SSO(SOL_TCP, TCP_KEEPCNT, conf->tcp_keepcnt);
    
  •   SSO(SOL_TCP, TCP_KEEPIDLE, conf->tcp_keepidle);
    
  •   SSO(SOL_TCP, TCP_KEEPINTVL, conf->tcp_keepintvl);
    

    +#ifdef NGX_DARWIN

  •   SSO(IPPROTO_TCP, TCP_KEEPALIVE, conf->tcp_keepintvl);
    

    +#else

  •   SSO(IPPROTO_TCP, TCP_KEEPCNT, conf->tcp_keepcnt);
    
  •   SSO(IPPROTO_TCP, TCP_KEEPIDLE, conf->tcp_keepidle);
    
  •   SSO(IPPROTO_TCP, TCP_KEEPINTVL, conf->tcp_keepintvl);
    

    +#endif

    undef SSO

      return NGX_DECLINED;
    

Incorrectly named variables

First of all thanks for this great module!

I've noticed when I compiled it and used it for the first time nginx wouldn't boot because it didn't recognize the tcp_keepidle and tcp_keepintvl variable.

In the file ngx_http_tcp_keepalive_module.c on line 97 , 113 and 121 the variable tcp_keepalive was declared three times. I've corrected the bottom two and now it seems to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.