2019独角兽企业重金招聘Python工程师标准>>>

  • 语法

    Syntax: upstream name {...}
    Default:--
    Context:http
  • 后端服务器在负载均衡调度中的状态:
    down 当前的server暂时不参与负载均衡
    backup 预留的备份服务器
    max_fails 允许请求失败的次数
    fail_timeout 经过max_fails失败后,服务暂停的时间
    max_conns 限制最大的接收的连接数
  • nginx 的调度算法:
    轮询  按时间顺序逐一分配到不同的后端服务器
    加权轮询   weight值越大,分配到的访问几率越高
    ip_hash 每个请求按访问IP的hash结果分配,这样来自同一个IP的请求,固定访问一个
    least_conn 最少连接数,哪个机器连接数少就分发
    url_hash 按照访问的URL的hash结果来分配请求,是每个URL定向到同一个后端服务器
    hash关键数值 hash自定义的key
  • 例 /etc/nginx/conf.d/default.con
    server {listen       8001;server_name  localhost;#charset koi8-r;access_log  /var/log/nginx/server.access.log  main;location / {root   /opt/app/code1;index  index.html index.htm;}
    ... ...
    }server {listen       8002;server_name  localhost;#charset koi8-r;access_log  /var/log/nginx/server.access.log  main;location / {root   /opt/app/code2;index  index.html index.htm;}
    ... ...
    }server {listen       8003;server_name  localhost;#charset koi8-r;access_log  /var/log/nginx/server.access.log  main;location / {root   /opt/app/code3;index  index.html index.htm;}
    ... ...
    }server {listen       80;server_name  localhost;#charset koi8-r;access_log  /var/log/nginx/test_proxy.access.log  main;location / {proxy_pass http://test_upstream;}
    ... ...
    }##普通轮询
    upstream test_upstream {server localhost:8001;server localhost:8002;server localhost:8003;
    }
  • 加权轮询
    upstream test_upstream {server localhost:8001;server localhost:8002 weight=5;server localhost:8003;
    }
  • 备份节点 
    upstream test_upstream {server localhost:8001 down; server localhost:8002 backup;server localhost:8003 max_fails=1 fail_timeout=10s;
    }
  • ip_hash 
    upstream test_upstream {ip_hash;server localhost:8001; server localhost:8002;server localhost:8003;
    }
  • url_hash  语法(1.7.2版本开始)
    Syntax: hash key [consistent];
    Default: --
    Context: upstream
    ##例:
    upstream test_upstream {hash $request_uri;server localhost:8001; server localhost:8002;server localhost:8003;
    }

转载于:https://my.oschina.net/langgege/blog/1930524

nginx学习九 upstream 负载均衡相关推荐

  1. Nginx学习4:负载均衡实例

    Nginx配置实例-负载均衡 目标 在浏览器地址栏输入地址 http://192.168.126.131:8080/edu/a.html,负载均衡效果,平均分配到 8080 和 8081 端口中 准备 ...

  2. 【Linux学习九】负载均衡

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 一.高并发 随着应用访问量的增加,带来高并发处理问题. 具体有两个: ...

  3. Nginx学习之十三-负载均衡-IP哈希策略剖析

    前面介绍过nginx负载均衡的加权轮询策略(http://blog.csdn.net/xiajun07061225/article/details/9318871),它是Nginx负载均衡的基础策略, ...

  4. Nginx面试三连问:Nginx如何工作?负载均衡策略有哪些?如何限流?

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 1.什么是Nginx,谈谈个人都理解,项目中是否用到,为什 ...

  5. 懂点 Nginx 反向代理与负载均衡,是面试加分项没有之一

    点击上方"方志朋",选择"置顶公众号" 技术文章第一时间送达! 学到老活到老 前端圈一直很新,一直要不停的学习,而且在进入大厂的路上,还要求熟悉一门后台语言等等 ...

  6. Nginx反向代理,负载均衡,redis session共享,keepalived高可用

    本站点停止更新,请访问:blog.coocap.com 相关知识自行搜索,直接上干货... 使用的资源: nginx主服务器一台,nginx备服务器一台,使用keepalived进行宕机切换. tom ...

  7. NGINX基于Tomcat配置负载均衡

    NGINX基于Tomcat配置负载均衡 本部署指南说明了如何使用NGINX开源和NGINX Plus在Apache Tomcat TM应用程序服务器池之间平衡HTTP和HTTPS流量.本指南中的详细说 ...

  8. Nginx反向代理与负载均衡等配置文件示例

    Nginx反向代理于负载均衡等配置文件示例 Nginx.conf配置文件 worker_processes 8;events {worker_connections 1024; }http {incl ...

  9. sql server代理无法启动_谁说前端不需要懂Nginx反向代理与负载均衡

    作者 | chenhongdong 链接 | https://juejin.im/post/5b01336af265da0b8a67e5c9 学到老活到老 前端圈一直很新,一直要不停的学习,而且在进入 ...

最新文章

  1. MySQL数据库-笔记03【范式(1NF、2NF、3NF)、查询练习题*10道(附解析)】
  2. Tensorboard--模型可视化工具
  3. 全国高等学校计算机水平考试总结,参加全国计算机等级考试的经历和总结
  4. 【Java数据结构与算法】第三章 双向链表和约瑟夫问题
  5. 【kafka】kafka 消费速度 小于 日志清理速度 (kafka数据被清理了)会发生什么 auto.offset.reset 参数
  6. 静默授权获取unionid_Asp.Net Core 中IdentityServer4 授权中心之自定义授权
  7. 对不起,离开平台,你什么都不是
  8. linux进入Mysql 的Dos控制台,dos进入mysql的实现方法
  9. 政府大数据应用案例,政府大数据治理方法
  10. 火狐浏览器Firefox怎样设置中文
  11. 行测测评——矩阵、圆形、环形三角图形数列推理解题技巧
  12. 74LS138的结构
  13. Python 实现电信天翼网关光猫自动重启
  14. Arduino_Core_STM32---pinMode()实现分析
  15. 圣杯布局和双飞翼布局
  16. 投稿状态(status)记录 IEEE wireless communications letters (IEEE WCL)
  17. linux下安装MySQL5.7及遇到的问题总结
  18. three.js使用外部模型创建动画,使用GLTF格式文件动画创建动画(vue中使用three.js71)
  19. 大学生如何在网上赚零花钱,适合学生党可做的零花钱项目
  20. 企查查api接口批量操作实战

热门文章

  1. 手机1像素线粗_小米1亿像素手机配置全曝光:史上最炫酷呼吸灯!
  2. 树莓派局域网文件共享samba
  3. u盘排序软件_华硕电脑u盘启动设置
  4. visual studio 怎么生成coredump文件_coredump详解
  5. 电脑屏保海底世界_想象不到!这些世界顶尖科技,掌握在谁的手里?
  6. 弱网测试用什么农_为什么用木蜡油做的家具,用甲醛测试仪测试会显示甲醛超标?...
  7. css使两个盒子并列_css如何去掉重叠部分的边框?
  8. thinkphp项目mysql类关系_ThinkPHP数据库与模型
  9. ros构建机器人运动学模型_古月私房课 | ROS机械臂开发中的主角MoveIt!
  10. debian 8 mysql_在Debian 8系统安装 nginx + php + mysql(MariaDB) 基本Web环境