X-Forwarded-For Header Explained
What the HTTP X-Forwarded-For header does and when it's used.
Published October 15, 2026
X-Forwarded-For lists the original client IP and any proxies a request passed through. Proxies append to it.
How it works
Applications behind load balancers read it to find the real client IP.
The X-Forwarded-For header is part of the HTTP message and is case-insensitive in name.
In a real exchange
curl -i https://example.com/
X-Forwarded-For: 203.0.113.9, 10.0.0.2
Practical examples
The header
X-Forwarded-For: 203.0.113.9, 10.0.0.2Set or use it in code
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;Inspect it
curl -sI https://example.com | grep -i 'x-forwarded-for'Common mistakes
- Trusting it from untrusted clients (spoofing)
- Using the wrong entry (take the right-most trusted)
- Not configuring trusted proxies in your framework
Key takeaways
- X-Forwarded-For: X-Forwarded-For lists the original client IP and any proxies a request passed through.
- Check it in browser DevTools → Network.
- Test with curl -I before deploying.
FAQ
How do I read the real IP?
Configure trusted proxies, then use the first untrusted address from the right.
Is X-Forwarded-For case sensitive?
Header names are case-insensitive; values may not be.