nginx 的upstream目前支持4种方式的分配

1、轮询(默认)

每个请求按时间顺序逐一分配到不同的后端服务器 ,如果后端服务器down掉,能自动剔除。

2、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。  
例如:
    upstream bakend {
         server 192.168.0.14 weight=10;
         server 192.168.0.15 weight=10;
    }

2、ip_hash 
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session 的问题。
例如:
    upstream bakend {
         ip_hash;
         server 192.168.0.14:88;
         server 192.168.0.15:80;
    }

3、fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
upstream backend {
    server server1;
    server server2;
    fair;
}

4、url_hash(第三方)

按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。

例:在upstream中加入hash语句,server语句中不能写入weight等其他的参数,hash_method是使用的hash算法

upstream backend {
    server squid1:3128;
    server squid2:3128;
    hash   $request_uri;
    hash_method crc32;
}

tips:

upstream bakend{#定义负载均衡 设备的Ip及设备状态
ip_hash;
    server 127.0.0.1:9090 down;
    server 127.0.0.1:8080 weight=2;
    server 127.0.0.1:6060;
    server 127.0.0.1:7070 backup;
}
在需要使用负载均衡的server中增加
proxy_pass http://bakend/ ;

每个设备的状态设置为:
1.down 表示单前的server暂时不参与负载
2.weight 默认为1.weight越大,负载的权重就越大。
3.max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
4.fail_timeout:max_fails次失败后,暂停的时间。
5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

nginx支持同时设置多组的负载均衡,用来给不用的server来使用。

client_body_in_file_only 设置为On 可以讲client post过来的数据记录到文件中用来做debug
client_body_temp_path 设置记录文件的目录 可以设置最多3层目录

location 对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡

nginx upstream的几种配置方式的更多相关文章

  1. 关于nginx upstream的几种配置方式

    平时一直依赖硬件来作load blance,最近研究Nginx来做负载设备,记录下upstream的几种配置方式. 第一种:轮询 upstream test{     server 192.168.0 ...

  2. nginx upstream的几种配备方式

     nginx upstream的几种配置方式 nginx 的upstream目前支持4种方式的分配 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器 ,如果后端服务器down掉,能自动剔 ...

  3. Nginx记录-nginx 负载均衡5种配置方式(转载)

    nginx 负载均衡5种配置方式 1.轮询(默认)   每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除.  2.weight 指定轮询几率,weight和访问比率成 ...

  4. nginx 负载均衡5种配置方式

    nginx 负载均衡5种配置方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight 指定轮询几率,weight和访问比率成正比, ...

  5. Nginx之upstream的四种配置方式

    1.轮询(weight)   指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况.默认当weight不指定时,各服务器weight相同,每个请求按时间顺序逐一分配到不同的后端服务 ...

  6. nginx upstream的五种分配方式

    Nginx负载均衡选项upstream用法举例 1.轮询(weight=1) 默认选项,当weight不指定时,各服务器weight相同,每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器d ...

  7. Nginx upstream的5种权重分配方式【转】

    原文地址:Nginx upstream的5种权重分配方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight指定轮询几率,weig ...

  8. c3p0三种配置方式(automaticTestTable)

    c3p0的配置方式分为三种,分别是http://my.oschina.net/lyzg/blog/551331.setters一个个地设置各个配置项2.类路径下提供一个c3p0.properties文 ...

  9. tomcat下jndi的三种配置方式

    jndi(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API.命名服务将名称和对象联系起来,使得我们可以用 ...

随机推荐

  1. Spring boot学习整理

    目录: Springboot结合hbase Springboot结合elasticsearch Springboot结合RestTemplate处理Http请求 Springboot的maven相关 ...

  2. keystone cache

    http://docs.openstack.org/juno/config-reference/content/section_keystone.conf.html http://docs.opens ...

  3. C#验证类

    #region 是不是中国电话,格式010-85849685 /**////<summary> /// 是不是中国电话,格式010-85849685 ///</summary> ...

  4. 字典:dict.c/dict.h

    Redis 源码分析(1):字典和哈希表(dict.c 和 dict.h)http://huangz.iteye.com/blog/1455808两个点:字典结构的运作流程哈希表的渐进式 rehash ...

  5. android中shape的属性

    <shape> <!– 实心 –> <solid android:color=”#ff9d77″/> <!– 渐变 –> <gradient an ...

  6. LeetCode OJ:Serialize and Deserialize Binary Tree(对树序列化以及解序列化)

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  7. ios6,ios7强制转屏

    在父视图控制器里面写如下代码 -(void)setViewOrientation:(UIInterfaceOrientation )orientation { if ([[UIDevice curre ...

  8. eclipse 环境 JUnit 测试框架(junit.framework.* 与 org.junit.*)

    如下所示,先通过 build path 导入 junit 环境依赖的 jar 包: 1. junit.framework.* junit.framework.* 主要类和函数: Test TestCa ...

  9. C++之结构体struct

    原创博客,转载请注明出处! 1.简介 # C++提供一些基本的数据类型(int,float,double,char等),但由于程序处理的问题通常较复杂,基本的数据类型不能满足程序需要,因此C++允许用 ...

  10. IntelliJ IDEA 代码检查规范QAPlug

    转自:http://blog.csdn.net/jizi7618937/article/details/51500725 Avoid Array Loops 数组之间的拷贝使用System.array ...