How to Get Real Client IPs in Fiber When Using a Reverse Proxy
Build robust and modern HTTP servers in Go with practical code examples and best practices.
Getting Real Client IPs in Fiber Behind a Proxy
When your Fiber application runs behind a reverse proxy like Caddy, Nginx, or Cloudflare, you’ll notice that c.IP()
returns the proxy’s IP address instead of your actual visitor’s IP. This happens because Fiber sees the direct connection, which is from the proxy server, not the original client.
Why This Happens
By default, Fiber reads the IP from the direct TCP connection for security reasons. Without proper configuration, it doesn’t know there’s a trusted proxy in front of it passing along the real client information in HTTP headers.