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. 【Bzoj 1835 基站选址】

    基站选址的区间里隐藏着DP优化的机密…… 分析:       不论是做过乘积最大还是石子合并,或者是其他的入门级别的区间DP题目的人呐,大米并认为读题后就能够轻松得出一个简洁明了的Dp转移方程.    ...

  2. 【python教程01】 编辑器

    工欲善其事,必先利其器.学习python,首先应该安装好开发中使用的编辑器. 那么在这里说一下我们推荐的两款:sublime text  && pycharm   为什么推荐这两款编辑 ...

  3. SSM实战

    http://www.07net01.com/2016/07/1607717.html https://github.com/Lutils/MyForum

  4. Mysql锁机制--并发事务带来的更新丢失问题

    Mysql 系列文章主页 =============== 刚开始学习 Mysql 锁的时候,觉得 Mysql 使用的是行锁,再加上其默认的可重复读的隔离级别,那就应该能够自动解决并发事务更新的问题.可 ...

  5. Java自定义注解的实现

    Java自定义注解的实现,总共三步(eg.@RandomlyThrowsException): 1.首先编写一个自定义注解@RandomlyThrowsException package com.gi ...

  6. NModBus的使用

    前言:最近在做一个项目,需要使用ModBus RTU与PLC进行通讯,现在将使用过程记录,以便备查. 一.什么是ModBus通讯协议 Modbus协议是应用于电子控制器上的一种通用语言,此协议支持传统 ...

  7. Structured Streaming + Kafka 集成中遇到的问题

    官方指导:http://spark.apache.org/docs/2.2.0/structured-streaming-kafka-integration.html 1.版本问题  起初用的kafk ...

  8. Kinect 深度图像格式

    Kinect的深度图像有16bit,2byte,如图: 第15位:标志位,不用做深度计算 第14~3位:深度图像数据,即距离,以毫米为单位 第0~2位:深度图中人的ID(PlayerID) 深度图有两 ...

  9. PHP MySQL Where 子句

    WHERE 子句 WHERE 子句用于提取满足指定标准的的记录. 语法 SELECT column_name(s) FROM table_name WHERE column_name operator ...

  10. C/C++ 函数指针

    函数声明 例如: float func(int, int); 以上就是一个函数的声明,要注意它的实际功能并没有被实现,换句话说就是它并没有被定义,只是声明此函数的存在.要想调用次函数,你必须对对此函数 ...