Design Nginx as a reverse proxy for two app servers with keepalive, timeouts and a health fallback.
IntermediateScenarioLoad Balancing, Proxies & CDN
Answer
Situation read → Typical hands-on config question.
What I'd do →
- Define the upstream:
upstream app { server 10.0.1.10:8080 max_fails=3 fail_timeout=10s; server 10.0.1.11:8080; keepalive 32; } - Proxy:
location / { proxy_pass http://app; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 3s; proxy_read_timeout 30s; } - Validate with
nginx -tand reload withnginx -s reload - Test failover by stopping one backend and watching
access.log
Why → Upstream keepalive avoids a new TCP handshake per request, and explicit timeouts prevent hung workers.
Interview tip → Say open source Nginx has only passive health checks.
More on Load Balancing, Proxies & CDN
What is the difference between a Layer 4 and a Layer 7 load balancer?BeginnerWhen do you choose an ALB and when an NLB in AWS?BeginnerForward proxy versus reverse proxy: what is the difference?BeginnerHow do health checks work on a load balancer and what makes a good one?BeginnerWhat are sticky sessions and why would you avoid them?BeginnerWhat does a CDN do and when does it help?Beginner