nginx 负载均衡示例
Devin hao Architect

upstream backend{
      #定义负载均衡设备的Ip及设备状态
      server 127.0.0.1:9090 down;
      server 192.168.1.12:8080 weight=2 ;
      server 192.168.1.13:6060 max_fails=3 fail_timeout=30s;
      server 192.168.1.14:7070 backup;
}
server{
    #…………………………
   location /{
        proxy_pass http://backend;
        #…………………………
    }
}

以上代码就是对负载均衡应用的示例。

Upstream可对后端服务器进行健康检查。

a) down表示当前的server暂时不参与负载。

b) weight默认为1.weight越大,负载的权重就越大。

c) _maxfails :在fail_timeout时间内对后台服务器请求失败的次数。

d) _failtimeout:max_fails次失败后,暂停的时间。

e) backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。