Nginx模块之SessionSticky
0?工作原理
?
Session Sticky?模塊在upstream?返回響應后,向客戶的瀏覽器寫入?Cookie?,默認名為route?,保存的內(nèi)容是一個?md5?碼。
之后,模塊接收到客戶瀏覽器的請求時,就根據(jù)?route?來決定將請求轉(zhuǎn)發(fā)到?upstream中哪臺服務器上。
?
這是源碼包中附帶的流程圖,將模塊的處理流程描述的非常清晰:
?
1?下載?Session Sticky
wget https://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz
?
2?安裝模塊
如果?Nginx?之前已經(jīng)安裝了,可以通過?nginx -V?命令查看當時編譯的參數(shù)。在參數(shù)后面追加安裝?Session Sticky?模塊的參數(shù),
避免影響之前?Nginx?已有模塊。
進入?nginx?源碼目錄,執(zhí)行命令:
./configure …? --add-module=/usr/local/src/nginx-sticky-module-1.1
?????????make
?????????make install
?
3?激活模塊
在?upstream塊中添加?sticky;?即可激活Session Sticky模塊。
?
upstream {
??sticky;
? server 127.0.0.1:9000;
? server 127.0.0.1:9001;
? server 127.0.0.1:9002;
}
?
4?可用選項
The "sticky" command can take several arguments to control its behaviour:
? sticky [name=route] [domain=.foo.bar] [path=/] [expires=1h] [hash=index|md5|sha1] [no_fallback];
?
| Configuration | Description | Parameters | Default Value |
| name | the name of the cookie used to track the persistant upstream srv | can be any string | "route" |
| domain | the domain in which the cookie will be valid | can be any string | nothing. Let the browser handle this. |
| path | the path in which the cookie will? ?? ?be valid | can be any path | nothing. Let the browser handle this. |
| expires | the validity duration of the cookie | must be a duration greater than one second | nothing. It's a session cookie |
| hash | the hash mechanism to encode upstream server. It cant' be used? ?? ?with hmac | md5|sha1 | md5 |
| hmac | The HMAC hash mechanism to encode upstream server. It's like? ?? ?the hash mechanism but it uses hmac_key to secure the hashing.? ?? ?It can't be used with hash. | md5|sha1 | none |
| hmac_key | The key to use with hmac. It's mandatory when hmac is set. | can be any string | none |
| no_fallback | When this flag is set, nginx will return a 502 (Bad Gateway orProxy Error) if a request comes? ?? ?with a cookie and the corresponding backend is unavailable. | no arguments | none |
來源:https://blog.csdn.net/dc_726/article/details/12348907
總結(jié)
以上是生活随笔為你收集整理的Nginx模块之SessionSticky的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: InnoDB与MyISAM中的count
- 下一篇: 送人的购物卡怎么办理