How do you make an nginx upstream resilient to a failing backend?
IntermediateProductionLoad Balancing, Proxies & nginx in Production
Answer
Use max_fails and fail_timeout for passive checks, proxy_next_upstream error timeout http_502 http_503 for idempotent requests only, proxy_connect_timeout 2s to fail fast, and a backup server. Active checks need nginx Plus, nginx_upstream_check_module or an alternative like HAProxy/Envoy.
Be careful: proxy_next_upstream retrying POSTs can duplicate side effects, so set proxy_next_upstream_tries and exclude non-idempotent methods.
More on Load Balancing, Proxies & nginx in Production
How do you choose between ALB, NLB and an nginx or Envoy fleet?IntermediateHow do you tune ALB idle timeout and backend keep-alive to avoid 502s?IntermediateWhich nginx directives matter most for a production reverse proxy?IntermediateHow do you do rate limiting and abuse protection in nginx?IntermediateHow do you achieve zero-downtime configuration reloads in nginx and HAProxy?IntermediateHow would you design a highly available load-balancing tier on-prem or in a colo?Advanced