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. poj3185 高斯消元

    The Water Bowls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5329   Accepted: 2081 D ...

  2. salt基本使用之一(1)

    1.帮助文档 以cmd函数为例子说下salt中的一些帮助信息 # 查看指定modules用法 salt '*' sys.doc cmd # 查看所有的modules列表 salt '*' sys.li ...

  3. C语言程序设计第一次实验

    一. 1.输入圆的半径,计算圆的面积周长问题 2流程图 3测试数据及运算结果 4实验分析 不会输入r,后来问了同学得到解决. 二. 1.输入一个四位年份,判断其是否是闰年.闰年的判别条件是概念年份能被 ...

  4. SQL之LIMIT ,OFFSET

    SELECT prod_name FROM Products LIMIT OFFSET ; LIMIT 4 OFFSET 3指示MySQL等DBMS返回从第3行(从0行计数)起的4行数据.第一个数字是 ...

  5. lgp20151222 java中如何将Object类型转换为int类型

    if (object instanceof Integer) {    Integer.parseInt(object.toString()); } 很简单是不是?我就想提醒下自己,java有个特殊词 ...

  6. angular.run和angular.config的区别

    ng的运行机制: config阶段是给了ng上下文一个针对constant与provider修改其内部属性的一个阶段 而run阶段是在config之后的在运行独立的代码块,通常写法runBlock 简 ...

  7. 软件测试assert

    之前实习做过一段时间测试,现做个总结: 实习测试的是一款CM系统(case 系统),来记录IT部门处理的维修,服务,反馈,预定服务等case:b/s架构,人少小项目,实习时间短,去了已经快完工,主要测 ...

  8. 关于html+ashx开发中几个问题的解决方法的感想和总结

    1.针对上篇文章中的服务端处理不敢苟同.仍然坚持使用反射,建立BaseHandler.ashx并在默认process方法中写上反射方法以及权限验证方法.针对具体的情况返回对应的值.服务端其他handl ...

  9. 原生JS实现圆周运动

    <body> <div id="ball" style="width:20px; height:20px; background:red; border ...

  10. python学习之路网络编程篇(第五篇)

    paramiko简介 paramiko 是基于Python实现的SSH2远程安装连接,支持认证及秘钥方式.可以实现远程命令执行.文件传输.中间SSH代理等功能. paramiko安装 #!/bin/b ...