]> git.kaiwu.me - nginx.git/commit
Upstream: added sticky sessions support for upstreams.
authorVladimir Homutov <vl@nginx.com>
Tue, 2 Apr 2013 21:44:36 +0000 (01:44 +0400)
committerAleksei Bavshin <a.bavshin@f5.com>
Mon, 9 Mar 2026 17:08:30 +0000 (11:08 -0600)
commit104734f21888cfec6994e092073f51a0d4b0fb47
tree7b63045b3921ee8ae2cacd5e6a79c7be829d507b
parentdff46cd1ae0095922e7eb9cf5b32ebe1e68a5706
Upstream: added sticky sessions support for upstreams.

Sticky sessions allow to route the same client to the same upstream server.

- upstream structures are extended to keep session-related information

- existing balancing modules are updated to provide an id of the selected
  server (SID) in pc->sid, and to select the server, given it's SID.

- other balancing modules are allowed to set the pc->hint value to choose
  the desired peer.  The sticky module will not change the hint if it's
  already set.

- the feature is enabled by default and can be disabled with the
  "--without-http_upstream_sticky" switch of the configure script.

The following configuration can be used to enable sticky sessions for
supported balancing modules:

    upstream u1 {
        server 127.0.0.1:8080;
        server 127.0.0.1:8081;

        sticky cookie server_id expires=1h domain=.example.com path=/;
    }

Co-authored-by: Ruslan Ermilov <ru@nginx.com>
Co-authored-by: Roman Arutyunyan <arut@nginx.com>
Co-authored-by: Maxim Dounin <mdounin@mdounin.ru>
13 files changed:
auto/modules
auto/options
src/event/ngx_event_connect.h
src/http/modules/ngx_http_upstream_hash_module.c
src/http/modules/ngx_http_upstream_ip_hash_module.c
src/http/modules/ngx_http_upstream_least_conn_module.c
src/http/modules/ngx_http_upstream_random_module.c
src/http/modules/ngx_http_upstream_sticky_module.c [new file with mode: 0644]
src/http/modules/ngx_http_upstream_zone_module.c
src/http/ngx_http_upstream.c
src/http/ngx_http_upstream.h
src/http/ngx_http_upstream_round_robin.c
src/http/ngx_http_upstream_round_robin.h