Rate limiting by client IP isn't working: attackers rotate the IP your app sees by sending their own `X-Forwarded-For` header.
AdvancedTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → The app (or nginx real_ip) takes the left-most XFF value, which the client fully controls. Or set_real_ip_from trusts 0.0.0.0/0, so any sender can set the "real" IP.
Diagnose →
curl -s -H 'X-Forwarded-For: 1.2.3.4' https://app.example.com/whoami
nginx -T | grep -E 'real_ip|set_real_ip_from'
If /whoami echoes 1.2.3.4, the header is trusted blindly.
Fix → Trust only your own proxies and take the right-most untrusted address:
set_real_ip_from 10.0.0.0/16; # your LB subnets only
set_real_ip_from 173.245.48.0/20; # e.g. CDN ranges, kept up to date
real_ip_header X-Forwarded-For;
real_ip_recursive on;
Prevent → Do rate limiting at the edge (CDN/WAF/ALB) where the TCP peer is the real client, and document which hops are trusted.
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.Intermediatenginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.Intermediate