一:下载,解压nginx sticky模块。

1
2
3
# cd /usr/local/src
# wget http://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz
# tar -zxvf nginx-sticky-module-1.1.tar.gz

二:查看现有nginx的编译参数,加上sticky模块参数重新编译。

1
2
3
4
5
#/usr/local/nginx/sbin/nginx –V
nginx version: nginx/1.3.14
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
TLS SNI support disabled
configure arguments: --prefix=/usr/local/nginx--user=nobody --group=nobody --with-select_module --with-poll_module--with-file-aio --with-http_ssl_module --with-http_realip_module--with-http_gzip_static_module --with-http_secure_link_module--with-http_sub_module --with-http_stub_status_module--add-module=/root/nginx-http-concat/

关闭nginx,加上sticky模块重新编译nginx(建议先备份配置文件)

1
2
3
4
# service nginx stop
# cd /usr/local/src/nginx-1.3.14
#./configure --prefix=/usr/local/nginx --user=nobody --group=nobody --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --add-module=/root/nginx-http-concat/ --add-module=/usr/local/src/nginx-sticky-module-1.1
# make && make install

三:修改配置文件,添加sticky相关参数

在类似如下位置添加参数(红色字体)

1
2
3
4
5
6
7
vi upstream.conf
upstream test.com
{
   sticky;                     ---sticky
   server192.168.1.17:9082 weight=5 max_fails=2 fail_timeout=30s;
   server192.168.1.81:9082 weight=5 max_fails=2 fail_timeout=30s;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#vi web.conf
server {
       listen       9082;
       server_name *.test.com;
       access_log /data/logs/test.com access_log;
       error_log  /data/logs/test.com.errorlog;
       set $proxy_pass test.com;
  
       location / {
           root   html;
           index index.html index.htm;
           proxy_set_header Host  $host:$server_port;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_pass  http://test.com;
           add_headerCache-Control no-store;
  
                  }

四:启动nginx,网页测试。

1
2
3
#/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
或者 
#service nginx start

 

Nginx sticky模块实现session粘滞的更多相关文章

  1. [转帖]利用nginx实现负载均衡 | 哈希算法,sticky模块实现session粘滞

    利用nginx实现负载均衡 | 哈希算法,sticky模块实现session粘滞 2018年08月02日 10:06:03 Minza 阅读数 483 https://blog.csdn.net/ha ...

  2. NGINX:sticky模块实现基于cookie的负载均衡

    Sticky模块 简述: 之前公司部署了一套网站及时发布系统,架构如下图所示:Nginx做前端代理,发布系统用tomcat运行,一台共享存储,一台数据库服务器:由于网站及时发布系统涉及到了用户登录操作 ...

  3. windows系统下nginx+tomcat+redis做负载均衡和session粘滞附整套解决方案

    Nginx: 在nginx-1.8.0\conf目录下找到nginx.conf文件,打开文件修改文件中http{}中的内容,在http{}中加入 upstream localhost  { serve ...

  4. nginx会话保持之sticky模块

    nginx会话保持之nginx-sticky-module模块 在使用负载均衡的时候会遇到会话保持的问题,常用的方法有:1.ip hash,根据客户端的IP,将请求分配到不同的服务器上:2.cooki ...

  5. 使用nginx sticky实现基于cookie的负载均衡

    在多台后台服务器的环境下,我们为了确保一个客户只和一台服务器通信,我们势必使用长连接.使用什么方式来实现这种连接呢,常见的有使用nginx自带的ip_hash来做,我想这绝对不是一个好的办法,如果前端 ...

  6. 使用nginx sticky实现基于cookie的负载均衡【转】

    在多台后台服务器的环境下,我们为了确保一个客户只和一台服务器通信,我们势必使用长连接.使用什么方式来实现这种连接呢,常见的有使用nginx自带的ip_hash来做,我想这绝对不是一个好的办法,如果前端 ...

  7. nginx负载均衡基于ip_hash的session粘帖

    nginx负载均衡基于ip_hash的session粘帖 nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除 ...

  8. nginx添加sticky模块-cookie保持会话

    cookie不同于session,一个存于客户端,一个存于服务端. 环境nginx 1.8.0 centos6.X sticky:1.2.5  wget https://bitbucket.org/n ...

  9. Linux中的特殊权限粘滞位(sticky bit)详解

    Linux下的文件权限 在linux下每一个文件和目录都有自己的访问权限,访问权限确定了用户能否访问文件或者目录和怎样进行访问.最为我们熟知的一个文件或目录可能拥有三种权限,分别是读.写.和执行操作, ...

随机推荐

  1. linux实操_shell流程控制

    if判断: 基本语法: if [ 条件判断式 ] then 程序 elif [ 条件判断式 ] then 程序 fi 实例:请编写一个shell程序,如果输入的参数,大于60,则输出“及格了”,如果小 ...

  2. VSCode:配置自动修复eslint

    { //"tfvc.location": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Profess ...

  3. .Net Core: 跨域Cros概要

    读取配置 public class AppConfig { public static IConfigurationRoot Configuration { get; set; } public st ...

  4. 项目:jSon和Ajax登录功能

    组件化网页开发 / 步骤二 · 项目:jSon和Ajax登录功能 要熟练编写封装的$.ajax({........})

  5. Oracle 物理结构(七) 文件-归档日志文件

    Oracle 物理结构(七) 文件-归档日志文件

  6. MySQL 中索引的长度的限制

    单列索引的长度的限制 (5.6里面默认不能超过767bytes,5.7不超过3072bytes): 起因是256×3-1=767.这个3是字符最大占用空间(utf8).但是在5.5以后,开始支持4个字 ...

  7. MySQL sql join 算发

    在MySQL中,可以使用批量密钥访问(BKA)连接算法,该算法使用对连接表的索引访问和连接缓冲区. BKA算法支持:内连接,外连接和半连接操作,包括嵌套外连接. BKA的优点:更加高效的表扫描提高了连 ...

  8. leetcode解题报告(11):Search Insert Position

    描述 Given a sorted array and a target value, return the index if the target is found. If not, return ...

  9. [USACO10HOL]赶小猪

    嘟嘟嘟 这题和某一类概率题一样,大体思路都是高斯消元解方程. 不过关键还是状态得想明白.刚开始令\(f[i]\)表示炸弹在点\(i\)爆的概率,然后发现这东西根本无法转移(或者说概率本来就是\(\fr ...

  10. Robot Framework(十九) 附录

    6附录 6.1测试数据中的所有可用设置 6.1.1设置表 Setting表用于导入测试库,资源文件和变量文件,以及定义测试套件和测试用例的元数据.它可以包含在测试用例文件和资源文件中.请注意,在资源文 ...