# Public entry point for laboratory 4. # # Docker's embedded DNS (127.0.0.11) returns every API replica IP for the # Compose service name "api". The shared upstream zone + "resolve" picks up # scale-up/scale-down and replacement containers without a reload. Passive # checks remove a replica after failed connections; proxy_next_upstream lets a # safe retry reach another backend. worker_processes auto; events { worker_connections 4096; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server_tokens off; access_log /dev/stdout; error_log /dev/stderr warn; resolver 127.0.0.11 valid=2s ipv6=off; upstream api_backend { zone api_backend 64k; server api:8080 resolve max_fails=3 fail_timeout=2s; keepalive 32; } server { listen 8080; # The API enforces 10 MiB; leave a little room for HTTP framing. client_max_body_size 12m; location / { proxy_pass http://api_backend; proxy_http_version 1.1; proxy_set_header Connection ""; 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_connect_timeout 2s; proxy_send_timeout 60s; proxy_read_timeout 60s; # Do not retry non-idempotent requests transparently. The client # repeats an uncertain POST with the same Idempotency-Key, which is # the contract-level guarantee across replicas. Application 503 # responses pass through unchanged. proxy_next_upstream error timeout http_502 http_504; proxy_next_upstream_tries 2; proxy_next_upstream_timeout 3s; } } }