Real client ip address to backend

Hello i'm running http router, which i need to pass the real client IP address to my backend.

Here is my router config :

rule = "Host(``)"
entryPoints = ["web"]
service = "app"
middlewares = "app"

    serversTransport = "app"
    url = "https://localhost:7996"
    url = "https://localhost:7997"

  insecureSkipVerify = true
  responseHeaderTimeout = "40s"
  dialTimeout = "40s"

    accessControlAllowMethods= ["GET", "OPTIONS", "PUT", "DELETE", "PATCH"]
    accessControlAllowHeaders= "*"
    accessControlAllowOriginList = "*"
    accessControlMaxAge = 100
    addVaryHeader = true

  certFile = "/etc//SSL/dev.crt"
  keyFile = "/etc//SSL/dev.key"
  stores = ["default"]

and my master.toml

  checkNewVersion = true

  insecureSkipVerify = true
  maxIdleConnsPerHost = 50
    dialTimeout = 40
    responseHeaderTimeout = 40
    idleConnTimeout = 40

    address = ":7998"
 options = "default"
        readTimeout = 30
        writeTimeout = 30        
      insecure = true
      trustedIPs = ["", ""]

    address = ":7780"

    directory = "/opt/traefik/config/routers"
	watch = true
	level = "DEBUG"
    filePath = "/var/log/traefik/traefik-error.log"
	format = "common"
	filePath = "/var/log/traefik/traefik-access.log"
	format = "common"

  dashboard = true
  insecure = true

  certFile = "/etc/SSL/dev.crt"
  keyFile = "/etc/SSL/dev.key"

How can I forward the IP address of the client to the backend?

Please note that this traefik is running by systemd daemon service.

This has been asked many times, so with a little searching you would probably found some solutions by yourself.

The connection will always have the IP of Traefik, this is how TCP/IP works.

When using http/s, you can check the headers which include the original IP.

Alternatively you can use ProxyProtocol, but the target service (application) needs to understand it.

I'm using HTTP, as I did not have any results when I'm using protocol 2 on TCP...

So does it mean every time the client is calling the traefik URL will generate a header where it's showing the client's IP address?

Traefik will always place the originating IP in the headers when forwarding http/s requests (X-Real-Ip).

1 Like

hi, thanks, can you give me example of config file what will be looking like based on my current config?

The headers are added automatically. Your target service just needs to read them from the http/s request.