# Lab3 edge load balancer. # # Docker's embedded DNS (127.0.0.11) returns one A record per running `api` # replica. `resolve` + a shared `zone` make nginx re-resolve that name every # `valid` seconds, so replicas that appear/disappear are picked up without a # reload. Passive checks (max_fails/fail_timeout) eject a replica that refuses # connections; proxy_next_upstream retries the same request on a healthy peer. worker_processes auto; events { worker_connections 2048; } http { resolver 127.0.0.11 valid=5s ipv6=off; resolver_timeout 2s; access_log /dev/stdout; error_log /dev/stderr warn; sendfile on; tcp_nopush on; keepalive_timeout 30; upstream api_backend { zone api_backend 64k; server api:8080 resolve max_fails=1 fail_timeout=5s; } server { listen 8080; server_name _; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Connection ""; proxy_connect_timeout 2s; proxy_send_timeout 30s; proxy_read_timeout 30s; # Retry a request on another replica if a backend is down mid-flight. proxy_next_upstream error timeout http_502 http_503 http_504; proxy_next_upstream_tries 2; proxy_next_upstream_timeout 5s; location /health/live { access_log off; proxy_pass http://api_backend; } location / { proxy_pass http://api_backend; } } }