0 工作原理



Session Sticky 模块在upstream 返回响应后,向客户的浏览器写入 Cookie ,默认名为route ,保存的内容是一个 md5 码。
之后,模块接收到客户浏览器的请求时,就根据 route 来决定将请求转发到 upstream中哪台服务器上。

这是源码包中附带的流程图,将模块的处理流程描述的非常清晰:


1 下载 Session
Sticky

wget https://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz


2 安装模块

如果 Nginx 之前已经安装了,可以通过 nginx
-V 命令查看当时编译的参数。在参数后面追加安装 Session Sticky 模块的参数,
避免影响之前 Nginx 已有模块。
进入 nginx 源码目录,执行命令:
./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


参考资料

1 使用nginx
sticky 模块实现基于 cookie 的负载均衡

2 官方网站
  

Nginx模块之SessionSticky的更多相关文章

  1. 结合源码看nginx-1.4.0之nginx模块组织结构详解

    目录 0. 摘要 1. nginx模块组织结构 2. nginx模块数据结构 3. nginx模块初始化 4. 一个简单的http模块 5. 小结 6. 参考资料 0. 摘要 nginx有五大优点:模 ...

  2. 【转】Nginx模块开发入门

    转自: http://kb.cnblogs.com/page/98352/ 结论:对Nginx模块开发入门做了一个helloworld的示例,简单易懂.也有一定的深度.值得一看. Nginx模块开发入 ...

  3. Nginx模块开发入门

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  4. Nginx模块fastcgi_cache的几个注意点 转

    Nginx模块fastcgi_cache的几个注意点   去年年底,我对nginx的fastcgi_cache进行摸索使用.在我的测试过程中,发现一些wiki以及网络上没被提到的注意点,这里分享一下. ...

  5. 开发Nginx模块

    开发Nginx模块 前面的哪些话 关于Nginx模块开发的博客资料,网上很多,很多.但是,每篇博客都只提要点,无法"step by step"照着做,对于初次接触Nginx开发的同 ...

  6. [转] Nginx模块开发入门

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  7. nginx模块开发获取post参数

    > 您好!>     我想请问下nginx模块里面怎么获取post参数,能有具体的代码更好!谢谢> 对于 "application/x-www-form-urlencode ...

  8. Nginx模块开发入门(转)

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  9. Nginx模块开发入门(转)

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

随机推荐

  1. ubuntu16.04安装eclipse后启动栏图标为问号

    ubuntu创建eclipse快捷方式图标. cd /usr/share/applications sudo touch eclipse.desktop sudo gedit eclipse.desk ...

  2. CentOs源码安装mysql-5.6.34(cmake)

    安装环境: VM11 CentOs6.7x86_64(Basic Server +Base System:Base\Compatlibility libraries\Debuggin Tools+De ...

  3. PHP 扩展开发检测清单(扩展开发必读)

    想要做出一个成功的 PHP 扩展包,不仅仅是简单的将代码放进文件夹中就可以了,除此之外,还有非常多的因素来决定你的扩展是否优秀.以下清单的内容将有助于完善你的扩展,并且在 PHP 社区中得到更多的重视 ...

  4. Android智能手机中各种音频场景下的audio data path

    上一篇文章(Android智能手机上的音频浅析)说本篇将详细讲解Android智能手机中各种音频场景下的音频数据流向,现在我们就开始.智能手机中音频的主要场景有音频播放.音频录制.语音通信等.不同场景 ...

  5. TeamViewer 服务队列网页怎么打开?有什么用?

    熟悉一款软件,除了要熟悉它的界面,还应该熟悉它的网站.可能会有很多人说,网站我当然知道了.但是TeamViewer的服务队列页面你真的熟悉吗?所以,今天小编就带大家深入的了解一下TeamViewer服 ...

  6. mysql 合并left join 数据条目

    查询两张关联表信息,原sql: SELECT * FROM  car_life_info c left JOIN shop_label sl ON  c.shop_id = sl.shop_id 出现 ...

  7. 如何用cmd通过sublime打开文件?

    sublime 提供了专门的命令工具subl.exe,就在它的安装目录之下,讲安装目录配置到系统环境变量中就OK了.具体如下: 1.找到sublime安装路径 如我的默认路径:C:\Program F ...

  8. 实践详细篇-Windows下使用VS2015编译安装Caffe环境(CPU ONLY)

    学习深度学习背景 最近在做一款抢票软件,由于12306经常检测账号状态,抢票抢着抢着就需要重新登录了,然后登录是需要验证码的.所以我最开始是想到了使用java基于感知哈希算法pHash做相似度匹配识别 ...

  9. MySQL where 子句

    MySQL where 子句 我们知道从MySQL表中使用SQL SELECT 语句来读取数据. 如需有条件地从表中选取数据,可将 WHERE 子句添加到 SELECT 语句中. 语法 以下是SQL ...

  10. 这是一个测试,测试markdown语法

    [TOC] 1. chpt1 这是一段话,前面没有空格 前面有4个空格,且在编辑状态下上面没有空行 前面有4个空格,且在编辑状态下上面有一个空行. 前面按了一下tab 1.1 1.1 2 段落1 前面 ...