This module is a load balancing module. It sticks the session between client and backend server via cookie. In such case, it guarantees that requests from the same client are distributed to the same server.
Example 1
# default: cookie=route mode=insert fallback=on |
Example 2
# insert + indirect mode: |
Directive
Syntax: session_sticky
[cookie=name] [domain=your_domain] [path=your_path ] [maxage=time] [mode=insert|rewrite|prefix] [option=indirect] [maxidle=time] [> maxlife=time] [fallback=on|off] [hash=plain|md5]
Default:session_sticky cookie=route mode=insert fallback=on
Context:upstream
Description:
This directive will turn on the session sticky module. Specific parameters are as follows:
cookiesets name of session cookie.domainsets domain of cookie. It is not set by default.pathsets url path of cookie. The default value is '/'.maxageset lifetime of cookie (cookie max-age attribute). If not set, it's a session cookie. It expires when the browser is closed.modesets mode of cookie:insert: This mode inserts cookie into http response via Set-Cookie header.
- prefix: This mode doesn't generate new cookie, but it inserts specific prefix ahead of cookie value of http response (e.g. "Cookie: NAME=SRV~VALUE"). When client(browser) requests next time with this specific cookie, it will delete inserted prefix before passing request to backend server. The operation is transparent to backend server which will get origin cookie .
- rewrite: In this mode, backend server can set cookie of session sticky itself. If backend server doesn't set this cookie in response, it disables session sticky for this request. In this mode, backend server manages which request needs sesstion sticky.
optionsets option value(indirect and direct) for cookie of session sticky. If setting indirect, it hides cookie of session sticky from backend server, otherwise the opposite.maxidlesets max idle time of session.maxlifesets max lifetime of session.fallbacksets whether it can retry others when current backend server is down.hashsets whether server flag in cookie is passed through plaintext or md5. By default, md5 is used.
Syntax: session_sticky_hide_cookie upstream=name;
Default: none
Context: server, location
Description:
This directive works with proxy_pass directive. It deletes cookie used as session sticky in insert+indirect and prefix mode, in which case cookie will be hidden from backend server. Upstream name specifies which upstream this directive takes effect in.