Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/nginx/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
告诉Nginx在出现错误时尝试另一个上游_Nginx_Load Balancing - Fatal编程技术网

告诉Nginx在出现错误时尝试另一个上游

告诉Nginx在出现错误时尝试另一个上游,nginx,load-balancing,Nginx,Load Balancing,我试图确定,当第一个选择的服务器返回特定错误时,是否可以告诉Nginx为指定的上游选择另一个服务器 例如: 这是你需要做的一个例子,你可以阅读更多的细节 Thx Mohammad,这与proxy_next_上游指令相结合完成了这项工作。 try upstream server 0 if it returns a certain error code (eg: 503) try upstream 1 else return response to client upstream

我试图确定,当第一个选择的服务器返回特定错误时,是否可以告诉Nginx为指定的上游选择另一个服务器

例如:


这是你需要做的一个例子,你可以阅读更多的细节


Thx Mohammad,这与proxy_next_上游指令相结合完成了这项工作。
try upstream server 0

if it returns a certain error code (eg: 503)
    try upstream 1
else
    return response to client
upstream myservers{
  #the first server is the main server
  server xxx.xxx.xxx.xxx weight=999 fail_timeout=5s max_fails=1;
  server xxx.xxx.xxx.xxx;
}

server {
    # all config
    proxy_pass http://myservers;
}