How to get client IP in Docker/Traefik?

Hello,

I have two Docker containers. One which runs Traefik, and one which runs Nginx. If I look in the logs of the Nginx container, I see the IP of the Traefik container which shares its Docker-network with the Nginx container. Is it possible to get the IP of the client in my logs? Or do I have to work with X-Real-IP?

Requests to your nginx app have the Traefik proxy IP as originating IP, as that's whats happening on the TCP/IP level. If you are looking for the original external client IP of the request, then check the HTTP X-Forwarded-For or X-Real-IP header.

Not sure how you can tell nginx to use a header IP instead of the connection IP in the logs.

Thank you for your answer. I have to look in to an issue, because the X-Real-IP and the X-Forwarded-For Header are both the IP of the Docker IP. So I have to do some researching..

Habe you tried setting required ports into host mode?

docker-compose.yml:

version: '3.9'

services:
  traefik:
    image: traefik:v2.9
    ports:
      - target: 80
        published: 80
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: tcp
        mode: host
    …

If you have a Load Balancer in front of your setup, check Traefik ProxyProtocol.