# Problem getting real IP from traefik

**URL:** <https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677>\
**Category:** Traefik v2\
**Tags:** docker-swarm\
**Created:** [June 26, 2020, 6:21pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677 "2020-06-26T18:21:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![felixsanz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/felixsanz/32/2216_2.png) [@felixsanz](https://community.traefik.io/u/felixsanz)\
**Post date:** [June 26, 2020, 6:21pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677/1 "2020-06-26T18:21:58Z")

</div>

I'm using docker swarm and I have an http service that redirects traffic from traefik to an nginx container. Inside the nginx config file i have this:

```auto
    real_ip_header X-Forwarded-For;
    set_real_ip_from traefik_proxy;

```

And of course i can ping it:

```auto
/ # ping traefik_proxy
PING traefik_proxy (10.0.27.110): 56 data bytes
64 bytes from 10.0.27.110: seq=0 ttl=64 time=0.100 ms

```

But.... nginx logs still show: `10.0.27.120 - - [26/Jun/2020:18:08:00 +0000] "GET /wp-content/upload...`. Notice is not the same IP as the ping one, but still not the user IP.

How can I fix it? Thanks!

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [June 27, 2020, 2:12pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677/2 "2020-06-27T14:12:39Z")

</div>

I have found the service port needs to be published using the host binding instead of ingress. The side effect being that only the host that is running traefik publishes the port.

This is [bypassing the routing mesh](https://docs.docker.com/engine/swarm/ingress/#bypass-the-routing-mesh)

---

<div class="post-metadata">

**Author:** ![felixsanz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/felixsanz/32/2216_2.png) [@felixsanz](https://community.traefik.io/u/felixsanz)\
**Post date:** [June 27, 2020, 4:05pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677/3 "2020-06-27T16:05:39Z")

</div>

what if ingress passes that variable to traefik? Maybe is traefik not receiving it

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [June 27, 2020, 4:14pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677/4 "2020-06-27T16:14:35Z")

</div>

Swarm ingress is operating at the TCP/UDP level, it is not able to add headers.

---

<div class="post-metadata">

**Author:** ![felixsanz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/felixsanz/32/2216_2.png) [@felixsanz](https://community.traefik.io/u/felixsanz)\
**Post date:** [June 28, 2020, 10:44pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677/5 "2020-06-28T22:44:39Z")

</div>

But I'm already using your method I think, and still can't get it to work.

```auto
services:
  proxy:
    image: "traefik:latest"
    deploy:
      mode: global
    ports:
      - target: 80
        published: 80
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: tcp
        mode: host

```

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [June 28, 2020, 10:48pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677/6 "2020-06-28T22:48:25Z")

</div>

Try running a `containous/whoami` container behind traefik, see what header is being set.

It might just be nginx configuration issue.

---

<div class="post-metadata">

**Author:** ![felixsanz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/felixsanz/32/2216_2.png) [@felixsanz](https://community.traefik.io/u/felixsanz)\
**Post date:** [June 29, 2020, 9:21pm UTC](https://community.traefik.io/t/problem-getting-real-ip-from-traefik/6677/7 "2020-06-29T21:21:19Z")

</div>

It works fine with the whoami container, but not with nginx ☹ any ideas about what can i do? I tried this but does not work: [https://stackoverflow.com/a/44648488](https://stackoverflow.com/a/44648488)

I think the problem is nginx getting the real ip from traefik. i don't know how to get it but it's not a problem with docker overlay network since traefik is receiving the correct ip already

EDIT: i think this works fine:

```auto
    real_ip_header X-Forwarded-For;
    set_real_ip_from traefik_proxy;

```

But you need an nginx container with the http\_realip\_module enabled
