原创

Web-nginx-多实例负载均衡-proxy_next_upstream-自动重试下一个服务器

两个负载均衡的环境,如果突然有一个挂了,接口会百分百请求到另一个实例吗?如果不可以会出现什么错误?==> 实际挂掉后,第一个接口请求会返回502,后面的才会请求到下一个服务器。

upstream backend { least_conn; # 最少连接 默认是轮询(round-robin)。还有其他如最少连接(least_conn)、IP 哈希(ip_hash)等 server backend1.example.com; server backend2.example.com; }location / { proxy_pass http://backend; #像 post, lock, patch 这种会对服务器造成不幂等的方法,默认是不进行重试的,如果一定要进行重试,则要加上这个non_idempotent配置 proxy_next_upstream error timeout http_500 http_502 http_503 http_504 non_idempotent; proxy_connect_timeout 5s; proxy_send_timeout 10s; proxy_read_timeout 10s; }

nginx的proxy_next_upstream使用中的一个坑
https://blog.csdn.net/qingyuwp/article/details/143458073

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
正文到此结束
本文目录