# How to get real IP behind two cascaded NGINX?

**URL:** <https://community.nginx.org/t/how-to-get-real-ip-behind-two-cascaded-nginx/1871>\
**Category:** NGINX\
**Tags:** docker, real-ip, networking\
**Created:** [April 5, 2025, 10:39pm UTC](https://community.nginx.org/t/how-to-get-real-ip-behind-two-cascaded-nginx/1871 "2025-04-05T22:39:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![allox](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@allox](https://community.nginx.org/u/allox)\
**Post date:** [April 5, 2025, 10:39pm UTC](https://community.nginx.org/t/how-to-get-real-ip-behind-two-cascaded-nginx/1871/1 "2025-04-05T22:39:27Z")

</div>

**What I’m trying to do** :  
I’ve setup one Nginx to act as a reverseproxy and to terminate https and forward the traffic by it’s incomming domain to several other webservices, also running as Nginx. All in an Docker environment.

`((Internet)) == :80/:443 ==> [nginx-proxy] == :80 ==> [service_a]`

In most of my services i need to know the IP of the caller from the Internet. Therefore i’ve added:

```auto
proxy_set_header X-Real-IP $remote_addr;

```

in the reverseproxy.

I’m using Docker 28.0.1 and Nginx 1.27.4 (all Containers)

**Where I’m stuck** :  
Sometimes i can see the real IP arriving at my services and sometimes i get 172.18.0.1 instead.

**What I’ve already tried** :  
I sometimes read that people where using the “host” network mode instead of “bridge”, but for me this is no option because a ran a lot of services using the same inbound-port and this only works in bridge (i think).

Looking at the reverseproxy Container network config if find this:

```auto
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.6",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,

```

So 172.18.0.1 is the gateway address of the bridge-network, which seem to not have a IPv6 address?

---

<div class="post-metadata">

**Author:** ![alessandro](https://drob5swvtjqxg.cloudfront.net/user_avatar/community.nginx.org/alessandro/32/4836_2.png) [@alessandro](https://community.nginx.org/u/alessandro)\
**Post date:** [July 3, 2025, 9:16pm UTC](https://community.nginx.org/t/how-to-get-real-ip-behind-two-cascaded-nginx/1871/2 "2025-07-03T21:16:04Z")

</div>

Heya! This does indeed seem like a Docker networking issue, especially given you are sometimes seeing the gateway address from the Docker network show up in the container.

---

<div class="post-metadata">

**Author:** ![system](https://drob5swvtjqxg.cloudfront.net/user_avatar/community.nginx.org/system/32/19_2.png) [@system](https://community.nginx.org/u/system)\
**Post date:** [August 2, 2025, 9:16pm UTC](https://community.nginx.org/t/how-to-get-real-ip-behind-two-cascaded-nginx/1871/3 "2025-08-02T21:16:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
