How to Forward the Real Client IP Through Traefik in Docker Swarm
Introduction In some applications, getting the real client IP address is critical. For example, web APIs, analytics systems, or rate-limiting middleware rely on it for logging, geo-location, or security. Normally, this is not a challenge. The backend can read the IP directly from X-Forwarded-For or the socket connection. However, when the application is deployed behind a Traefik proxy and running as a Docker Swarm service, things become complicated. The Issue Understanding the Request Path When an application is deployed behind Traefik in Swarm, one might assume the network request path is straightforward: ...