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 cookie
set $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;

}

最新文章

  1. SQL Server2008从入门到全面精通 SQL数据库视频教程
  2. JAVA应用程序占用CPU、内存过高分析过程
  3. 部署Eclipse中的Web项目到Tomcat服务器运行
  4. mvc理念和thinkphp的语法特征 thinkphp引入模板
  5. 设置ViewController 数据源无法改变view
  6. oracle启动,提示“LRM-00109: could not open parameter file”
  7. ci 笔记
  8. 简单的web三层架构系统【第一版】
  9. Provably Delay Efficient Data Retrieving in Storage Clouds---INFOCOM 2015
  10. Linux下关闭Tomcat残留线程
  11. Ubuntu等Linux系统显卡性能测试软件 Unigine 3D
  12. IdentityServer4(9)- 使用OpenID Connect添加用户身份验证(implicit)
  13. Linux操作系统加固
  14. MATLAB:图像的与、或、非、异或逻辑运算(&、|、~、xor)
  15. King Arthur's Birthday Celebration
  16. verilog语法实例学习(2)
  17. asp.net gridview 如何实现行点击事件
  18. 洛谷P3599 Koishi Loves Construction 构造
  19. Oracle11g温习-第一章 2、ORACLE 物理结构
  20. 软工网络15团队作业8——Beta阶段敏捷冲刺(Day6)

热门文章

  1. IList,List<T>转换为DataTable 常用收藏
  2. 【bzoj 4046 加强版】Pork barrel
  3. springboot jpa 创建数据库以及rabbitMQ分模块扫描问题
  4. nginx第三天
  5. Attention机制中权重的计算
  6. SpringMVC页面中文乱码
  7. 【leetcode】801. Minimum Swaps To Make Sequences Increasing
  8. Tarjan求强连通分量、求桥和割点模板
  9. 51 Nod 1486 大大走格子
  10. 家谱(gen)x