で、それをバックエンドにしてさらにNginxでロードシェアする時の設定。

バックエンドのunicornが健在の時はフロント<=>バック間のレスポンスは上図のようになり、適当にロードシェアされます。
nginxのデフォルト設定ではバックエンドがunicornの状態に応じて502を返す際にも、フロントは気にしません。

上図の状態になってもupstream対象を調整せずに、200, 502, 200, 502 とレスポンスを返します。
そりゃ困るということでドキュメントを参照、 HttpProxyModuleのproxy_next_upstream を使ってupstreamのポリシーを指定すればOKです。
デフォルトだとこうなっているので、
"proxy_next_upstream error timeout;"
http_502 を足してあげれば502を回避するようになります。
"proxy_next_upstream error timeout http_502 http_503;"
0 件のコメント:
コメントを投稿