如果独angular兽重载并返回502,nginx可以重试吗?

在将502返回给客户端之前是否有可能让nginx重试第二个后端?

会这样的工作吗?

前端:

# haproxy:85 => [a few app servers]:8000 # more specifically: # haproxy => [nginx => unicorn (502 when busy)] # Will this try a second app server when the first returns 502? upstream haproxy { server 127.0.0.1:85; server 127.0.0.1:85 backup; } server { listen 80; proxy_pass http://haproxy; proxy_next_upstream http_502; } 

后端:

 upstream unicorn { server unix:/tmp/unicorn.sock fail_timeout=0; } server { listen 8000; proxy_pass http://unicorn; } 

无论如何,我只是好奇。 这实际上可能是相当愚蠢的,因为重试可能最终会击中相同的重载服务器,并最终返回502无论如何…

据我所知,Nginx自动尝试每个可用的服务器 – 如果全部返回错误,它将返回最后一个响应的错误代码。

proxy_next_upstream似乎提供了一些更好的控制,哪些错误将被处理,哪些将被忽略(但默认已经是连接,发送或接收的任何“错误”,我相信,60秒超时)。

根据文件(措辞可以使用一些工作):

“如果试图与服务器发生错误,则请求将被传输到下面的服务器,然后直到所有服务器的工作人员都没有被testing。如果成功的答案没有成功地从所有的服务器获得,那么到客户端将会返回最后一台服务器的工作结果。“

您可以使用脚本来validation这种行为,该脚本会将时间(或任何数据)logging到文件中,并返回502.如果只发现1行logging,则nginx不会尝试多个服务器,如果发现logging了两行, 。