nginx upstream负载均衡配置
nginx upstream 负载均衡的几种分配方式:
- 轮训
- 权重
- ip_hash
示例
upstream api {
ip_hash; # ip_hash方式
server 192.168.0.100:8000 weight=1 down; # weight 权重分配,值越大分配越多 down表示不参与分配
server 192.168.0.101:8000 backup; # 备份,只有其它失效才会转发到它
server 192.168.0.102:8000 weight=1;
server 192.168.0.103:8000 weight=0.5;
server 192.168.0.104:8000 max_fails=3 fail_timeout=30s; # 表示30秒内失败3次或以上则认为它已经挂掉
}