Session persistence through ip_hash has some drawbacks, which are achieved through the client ip address. In the same network, many client access servers will be thrown to the same machine, or CDN will also cause load imbalance. Therefore, we need to implement session persistence through client cookies, including F5 and session persistence on Sangfor devices, which are also implemented by inserting cookie values. The next time the client accesses the server, it carries a local cookie. The sticky module in nginx analyzes and throws it to the corresponding server.
Software version:
Nginx-1.6.0 (later nginx-1.2.3)
Nginx-sticky-module-1.1
Installation:
[Root @ localhost nginx-1.6.0] #./configure-prefix =/usr/local/nginx/-add-module = ../nginx-sticky-module-1.1
[Root @ localhost nginx-1.6.0] # make
Make:
Objs/addon/nginx-sticky-module-1.1/ngx_http_sticky_misc.o] Error 1
Reference solution:
Method 1:
Http://www.blogjava.net/sliverfancy/archive/2014/03/28/411594.html
It indicates that openssl-devel has been installed and is invalid.
Method 2 (not tested ):
Nginx-1.5.x and nginx-sticky-module-1.1 compilation will be a bit problematic, it should be the nginx new version does not have the corresponding nginx-sticky-module, the solution is to change the 281 line of nginx-sticky-module-1.1/ngx_http_sticky_misc.c:
Digest-> len = ngx_sock_ntop (in, sizeof (struct sockaddr_in), digest-> data, len, 1 );
Method 3:
Reduce nginx version, I here for nginx-1.2.3 compiled through.
The sticky module parameters are only used in the upstream segment and cannot coexist with ip_hash.
Supported parameters:
Sticky [name = route] [domain =. foo. bar] [path =/] [expires = 1 h] [hash = index | md5 | sha1] [no_fallback];
Name: can be any string character. The default value is route.
Domain: Which domain names can use this cookie?
Path: which path pairs enable sticky, such as path/test, so only the test directory will use sticky for load balancing
Expires: cookie expiration time. By default, the browser expires when it is disabled, that is, the session mode.
No_fallbackup: if the cookie server is down, 502 (bad gateway or proxy error) is returned.
Configuration Reference (reverse proxy omitted ):
Upstream apache {
Sticky name = srv_id expires = 1 h domain = .test.com path = /;
Server 192.168.5.4 max_fails = 3 fail_timeout = 20 s;
Server 192.168.5.5 max_fails = 3 fail_timeout = 20 s;
}