Nginx负载均衡服务器实现会话粘贴的几种方式
1、 使用Nginx 的ip_hash作为负载均衡服务并支持Session sticky
2、 使用nginx sticky第三方模块实现基于cookie的负载均衡
3、使用nginx的map指令根据cookie分流:
map $COOKIE_abcdexpid $group {~*1$ apache001;~*2$ apache002;default root; }upstream apache001 {server 192.168.1.1:8080 weight=1 max_fails=1 fail_timeout=30s; }upstream apache002 {server 192.168.1.2:8080 weight=1 max_fails=1 fail_timeout=30s; }upstream root {server 192.168.1.0:8080 weight=1 max_fails=1 fail_timeout=30s; }server {listen 8080;server_name neoremind.net;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" "group=$group"''"$http_user_agent" $gzip_ratio $request_time "$http_x_forwarded_for"';access_log logs/access_log main;error_log logs/error_log;location / {proxy_pass http://$group;proxy_set_header X-Forwarded-For $remote_addr;} }
4、 利用set和if…else… 根据cookie分流
upstream apache001 {server 192.168.1.1:8080 weight=1 max_fails=1 fail_timeout=30s; }upstream apache002 {server 192.168.1.2:8080 weight=1 max_fails=1 fail_timeout=30s; }upstream root {server 192.168.1.0:8080 weight=1 max_fails=1 fail_timeout=30s; }server {listen 8080;server_name beidoutest.baidu.com;#match cookieset $group "root";if ($http_cookie ~* "abcdexpid=([^;]+)(1$)"){set $group apache001;}if ($http_cookie ~* "abcdexpid=([^;]+)(2$)"){set $group apache002;}log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" "group=$group"''"$http_user_agent" $gzip_ratio $request_time "$http_x_forwarded_for"';access_log logs/access_log main;error_log logs/error_log;location / {proxy_pass http://$group;proxy_set_header X-Forwarded-For $remote_addr;}}
5、nginx1.7.2版本后提供的hash方法:
# http context upstream backend_hosts { hash $cookie_jsessionid consistent; server host1.example.com; server host2.example.com; server host3.example.com;
}
本文来自:Linux学习网
转载于:https://blog.51cto.com/9820344/1605587
Nginx负载均衡服务器实现会话粘贴的几种方式相关推荐
- 基于宝塔搭建nginx负载均衡服务器
准备三台服务器,搭建好宝塔环境 服务器1:作为主服务器,分发服务器,并且数据库,redis等都装在此服务器 服务器2:均衡服务器1 服务器3:均衡服务器2 打开端口:如果使用阿里云,配置安全组,888 ...
- 两台linux服务器负载均衡代码实现,nginx实现负载均衡,nginx负载均衡确保两台服务器数据保...
nginx实现负载均衡,nginx负载均衡确保两台服务器数据保 一.准备篇: Nginx 负载服务器: Centos 6.2 IP:192.168.1.93 WEB服务器: Web1:192.168. ...
- 单一nginx负载均衡+LNMP分布式架构
随着互联网的快速发展,我们的web站点访问量和数据流量的快速增长,对于我们服务器的处理能里的要求也越来越高,这样的情况下,单一的服务器根本无法承受, 这样的话我们丢弃掉原有的设备,做硬件升级,会造成 ...
- Nginx系列篇二:linux搭建Nginx负载均衡
建议先搭建好Nginx环境 可阅读--->Linux中搭建Nginx 1.准备好三台服务器[标配] 一.nginx负载均衡服务器:192.168.102.110,配置好Nginx 二.tomca ...
- Nginx负载均衡配置策略
转自:http://www.freeoa.net/osuport/cluster/nginx-load-equilibrium-configuration-strategy_1652.html Ngi ...
- nginx负载均衡和高可用
代理和负载均衡的区别 代理负责把连接请求直接转发到后台某个web节点 负载均衡负责把请求使用某种调度算法分散发布给后台所有web节点 ----------------------------- ...
- nginx负载均衡案例(1)
nginx负载均衡案例详解 随着网站.应用访问量的增加,一台服务器已经不能满足应用的需求,而需要多台服务器集群,这时就会用到负载均衡,nginx负载均衡有多种算法,本篇文章通过举例讲解nginx负载均 ...
- 使用nginx负载均衡后,微信公众号报错:redirect_uri域名与后台配置不一致,错误码:10003
环境: nginx负载均衡服务器:192.168.1.18 IIS节点服务器:192.168.1.12 IIS节点服务器:192.168.1.16 说明: 公司IIS网站中有配置判断域名, 通过ngi ...
- NGINX负载均衡配置解析
课程目标 掌握什么是负载均衡及负载均衡的作用和意义. 了解lvs负载均衡的三种模式. 了解lvs-DR负载均衡部署方法. 掌握nginx实现负载均衡的方法. 掌握lvs+nginx负载均衡拓扑结构. ...
- 负载均衡服务器的搭建(linux)
Nginx简单介绍以及linux下使用Nginx进行负载均衡的搭建 转载至:https://blog.csdn.net/liboyang71/article/details/77371595 今天我们 ...
最新文章
- MYSQL 深入浅出索引(下)
- 火狐插件火狐***插件将Firefox变成***工具的七个插件
- AIX操作系统启动详细介绍
- 火狐浏览器打印网页不全_武汉社保网上下载打印流程
- k8s里面的项目怎么暴露端口让用户访问_从零开始入门 K8s | 可观测性:监控与日志...
- gradle ant_使用Gradle引导旧式Ant构建
- Spring对象绑定与类型转换
- 【poj3358】消因子+BSGS 或 消因子+欧拉定理 两种方法
- 刀塔传奇公会管理系统 ------ Python界面访问Pgsql
- 01_11_Strtus2简单数据验证
- 【渝粤教育】21秋期末考试组织行为学10068k2
- java jre 1.8_安装java1.8和配置环境变量
- 鸡啄米VS2010/MFC编程入门教程系列
- 有自学能力的人,赚钱极其简单—聚财云库
- zynqMP LINUX 启动流程和移植
- 关于720p和1080p观看距离和效果
- 角位移/倾角/角度传感器如何安装
- 4.4 使用倾斜工具和整形工具制作图标 [Illustrator CC教程]
- Dynamics 365 Command Checker for Ribbons
- 输入法十年战事:为何夺冠的是第三方?