Interview Prep/Networking/Load balancers and reverse proxies

A backend behind nginx moved to a new IP (DNS updated), but nginx keeps sending traffic to the old IP until reload.

AdvancedTroubleshootingLoad balancers and reverse proxies
Answer

Likely causes → When proxy_pass uses a literal hostname (or an upstream with hostnames in open-source nginx), nginx resolves it once at startup/reload and caches the IPs forever, ignoring TTL. Common with ELB hostnames, whose IPs change.

Diagnose →

dig +short backend.internal
sudo ss -tnp | grep nginx | awk '{print $5}' | sort | uniq -c   # still connecting to old IP

Fix → Force runtime resolution by using a variable plus a resolver:

resolver 10.0.0.2 valid=30s ipv6=off;
location / {
    set $backend "http://backend.internal:8080";
    proxy_pass $backend;
}

nginx 1.27.3+ also supports server backend.internal resolve; inside an upstream block with a zone.

Prevent → Never proxy to ELB/cloud hostnames without dynamic resolution; reload nginx in deploy pipelines when upstreams change.

All Networking questions Roadmap: Networking for DevOps

More on Load balancers and reverse proxies