- Newest
- Most votes
- Most comments
What you see is expected behavior with most AWS load balancers, which append their IP to the X-Forwarded-For header. If you’re using an ALB or NLB with a proxy protocol, the client IP comes first, followed by intermediary IPs. So yes, your app needs to either parse the first IP in the list, or you can configure your reverse proxy (like Nginx) to extract it cleanly.
If you're using Nginx in front, I’d suggest this directive: nginx real_ip_header X-Forwarded-For; set_real_ip_from <load-balancer-ip-or-CIDR>; real_ip_recursive on;
This will make Nginx treat the first IP in the X-Forwarded-For chain as the real client. You don't need to change the load balancer unless it's appending something unnecessary (like NAT IPs from upstream proxies).
Also worth double-checking if the app logic is parsing $_SERVER['HTTP_X_FORWARDED_FOR'] naively. A simple explode(',', ...) with trim() on the first entry usually fixes this.
Relevant content
- asked 3 years ago
- AWS OFFICIALUpdated a month ago
