Nginx Sticky session is mainly realized by Nginx-sticky-module
1 downloads nginx-sticky-module
: https://code.google.com/p/nginx-sticky-module/downloads/list
Official Document: Https://code.google.com/p/nginx-sticky-module/wiki/Documentation
2 installation
Unzip Nginx-sticky-module to/usr/local
Tar-xzf nginx-sticky-module-1.1.tar.gz
Enter the Nginx source directory/usr/local/nginx-1.6.2, execute the command, recompile:
./configure.--add-module=. /nginx-sticky-module-1.1makemake Install
3 Make Error
The following error may occur due to a high version of Make:
MAKE[1]: * * * [OBJS/ADDON/NGINX-STICKY-MODULE-1.1/NGX_HTTP_STICKY_MISC.O] Error 1make[1]: Leaving directory '/usr/ local/nginx-1.6.2 ' Make: * * * [build] Error 2
Workaround:
The 281 lines of NGINX-STICKY-MODULE-1.1/NGX_HTTP_STICKY_MISC.C are modified to:
Digest->len = Ngx_sock_ntop (in,sizeof (struct sockaddr_in), Digest->data, Len, 1);
4 Sticky Use
Upstream 172.16.0.16 { sticky; Server 172.16.0.17:8180; Server 172.16.0.17:8280; Server 172.16.0.18:8180; Server 172.16.0.18:8280; }
Sticky supported parameters:sticky [Name=route] [Domain=.foo.bar] [path=/] [expires=1h] [HASH=INDEX|MD5|SHA1] [ no_fallback];
Name: can be any string character, default is routedomain: which domain name can be used under this cookiepath: which path to enable sticky, for example path/test, Then only test this directory will use sticky do load balancing Expires:cookie expiration time, the default browser close expires, that is, session mode. No_fallbackup: If this is set, the server of the cookie is down, then it will return 502 (Bad gateway or proxy error), it is recommended not to be enabled.
As follows:
Sticky Name=routeid expires=1h domain=.test.com path=/;
Nginx Session Sticky