nginx失败重试 proxy_next_upstreasm指
Syntax:proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 |http_403 | http_404 | http_429 | non_idempotent | off ...;
Default:proxy_next_upstream error timeout;
Context:http, server, location
Syntax:proxy_next_upstream_tries number;
Default:proxy_next_upstream_tries 0;
Context:http, server, location
Syntax:proxy_next_upstream_timeout time;
Default:proxy_next_upstream_timeout 0;
Context:http, server, location
例如:
upstream backend {
server 192.168.137.138;
server 192.168.137.201;
server 192.168.137.138:8080; #存在aaa.html路径
}
#只有192.168.137.138:8080; #存在aaa.html路径;
server {
listen 5658;
server_name test;
proxy_next_upstream http_404;
proxy_next_upstream_tries 1;
proxy_next_upstream_timeout 5s;
location / {
proxy_pass http://backend;
}
}
对于RR算法访问如果命中192.168.137.138后端
如果 proxy_next_upstream_tries 1; 则访问192.168.137.138如果返回404, 则返回404给客户端
如果 proxy_next_upstream_tries 2; 则访问192.168.137.138失败一次, 会继续将请求发送给
下一个后端 192.168.137.201, 如果192.168.137.201返回404, 则返回404给客户端
如果 proxy_next_upstream_tries 3; 则访问192.168.137.138失败一次,
会继续将请求发送给下一个后端 192.168.137.201, 如果192.168.137.201返回404,
则 会继续将请求发送给下一个后端 192.168.137.201:8080, 因为192.168.137.201:8080
存在aaa.html, 所以将aaa.html返回给客户端。