一:下载,解压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. Django REST framework+Vue 打造生鲜电商项目(笔记二)

    (转自https://www.cnblogs.com/derek1184405959/p/8768059.html)(有修改) 接下来开始引入django resfulframework,体现它的强大 ...

  2. BZOJ 3901 棋盘游戏 (找结论+枚举+贪心)

    题面 略 BZOJ 传送门 分析 具体分析见 dalao博客 妙就妙在当i<x,j<xi<x,j<xi<x,j<x时,(i,j)(i,j)(i,j) ^ (i,x) ...

  3. Codeforces Round #539 (Div. 1) 1109F. Sasha and Algorithm of Silence's Sounds LCT+线段树 (two pointers)

    题解请看 Felix-Lee的CSDN博客 写的很好,不过最后不用判断最小值是不是1,因为[i,i]只有一个点,一定满足条件,最小值一定是1. CODE 写完就A,刺激. #include <b ...

  4. Activation HDU - 4089 (概率DP)

    kuangbin的博客 强 #include <bits/stdc++.h> using namespace std; const int MAXN = 2005; const doubl ...

  5. Codeforces Round #584 A. Paint the Numbers

    链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...

  6. 用pyinstaller打包python程序、打包pyqt程序

    将.py脚本拷贝到一个文件夹中: 然后shift+右键,打开Powershell窗口: -F:设置打包为一个.exe文件.(缺点打开速度慢,不加-F则不打包为一个.exe,优点简洁方便) -w:设置不 ...

  7. Codeforces Round #599 (Div. 2) A,B1,B2,C 【待补 D】

    排序+暴力 #include<bits/stdc++.h> using namespace std; #define int long long #define N 1005000 int ...

  8. MySQL 源码编译安装脚本

    cat mysql_init.shmysql_init.sh               mysql_init.sh.20190401      mysql_init.sh.back20171030  ...

  9. 关于安卓端 点击button时出现橙色边框

    一开始我以为是安卓的原因,后来经过测试发现不是,出现这个情况应该button的outline属性生效了,但是我已经写了outline 为none,后来发现,需要写上:foucs{ outline:0 ...

  10. 添加sql距离现在多久以前时间条件

    UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(add_time)<=25200 其中now()是现在时间 add_time是其他时间点  25200:是秒,现在和ad ...