# Getting IP forward to work with IP Restriction plugin and proxy NGINX

**URL:** <https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740>\
**Category:** General\
**Created:** [August 23, 2018, 9:58am UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740 "2018-08-23T09:58:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![grillorafael](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/grillorafael/32/170_2.png) [@grillorafael](https://discuss.konghq.com/u/grillorafael)\
**Post date:** [August 23, 2018, 9:58am UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/1 "2018-08-23T09:58:12Z")

</div>

Hi all,

I run Kong through DCOS and I have a edge machine that runs our edge nginx.

So what we have is like the following:

DOMAIN1 -\> EDGE NGINX -\> KONG

I’m trying to use ip restriction plugin but when the IP arrives in Kong, it is the EDGE machine internal network’s ip (10.250.3.2).

I have the following configuration in the Edge nginx:

```auto
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection "";

```

And Kong is configured as follows:

```auto
KONG_TRUSTED_IPS: 0.0.0.0/0,::0 
KONG_REAL_IP_RECURSIVE: on
KONG_REAL_IP_HEADER: X-Forwarded-For

```

I’m running kong 0.14.1

If I put `10.250.3.2` in the ip restriction plugin, it works well but it doesn’t if I use my external ip.

---

<div class="post-metadata">

**Author:** ![bruno.bornia](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bruno.bornia](https://discuss.konghq.com/u/bruno.bornia)\
**Post date:** [August 23, 2018, 5:01pm UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/2 "2018-08-23T17:01:42Z")

</div>

I have very similar use case, and I am currently trying to workaround it. Would be very good to have a solution for that.

---

<div class="post-metadata">

**Author:** ![grillorafael](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/grillorafael/32/170_2.png) [@grillorafael](https://discuss.konghq.com/u/grillorafael)\
**Post date:** [August 27, 2018, 7:34am UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/3 "2018-08-27T07:34:26Z")

</div>

Anyone can help with the issue?

---

<div class="post-metadata">

**Author:** ![kikito](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/kikito/32/15_2.png) [@kikito](https://discuss.konghq.com/u/kikito)\
**Post date:** [August 27, 2018, 2:20pm UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/4 "2018-08-27T14:20:47Z")

</div>

Hi,

Your config seems correct at a first glance. First of all make sure that your EDGE nginx has [reloaded that config](http://nginx.org/en/docs/beginners_guide.html#control) after you changed it, and make sure to [reload Kong as well](https://docs.konghq.com/0.14.x/cli/#kong-reload).

If that doesn’t work, you will have to debug the problem. I would recommend starting by adding a logging plugin to Kong (you could use [file-log](https://docs.konghq.com/plugins/file-log/), or [any other logging plugin](https://konghq.com/plugins/#logging) if it suits you better) so you can see which requests Kong is receiving, and especially the headers.

If you can’t find the issue that way, you should do something similar with your EDGE machine, although the process might be more involved - it might involve manually changing your config to write down requests in your logs.

If you still can’t find the problem after that, please include a sample of each here- the headers in particular should be particularly useful.

---

<div class="post-metadata">

**Author:** ![grillorafael](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/grillorafael/32/170_2.png) [@grillorafael](https://discuss.konghq.com/u/grillorafael)\
**Post date:** [August 27, 2018, 2:35pm UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/5 "2018-08-27T14:35:30Z")

</div>

I’ll give it a try with file logging and see what happens. I tried on EDGE to set the response header with the same values as the proxy ones and I got the expected header values.

But I’ll check with the file log and I’ll let you know.

---

<div class="post-metadata">

**Author:** ![grillorafael](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/grillorafael/32/170_2.png) [@grillorafael](https://discuss.konghq.com/u/grillorafael)\
**Post date:** [August 27, 2018, 2:51pm UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/6 "2018-08-27T14:51:15Z")

</div>

Hi @kikito for some reason the header was not reaching Kong. Those directives are set under `http` namespace but it seems to work only when I add to `location / {}` block. Do you have any idea why this can happen?

I thought that by adding to `http {}` block it would apply to everything below it.

---

<div class="post-metadata">

**Author:** ![grillorafael](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/grillorafael/32/170_2.png) [@grillorafael](https://discuss.konghq.com/u/grillorafael)\
**Post date:** [August 27, 2018, 3:08pm UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/7 "2018-08-27T15:08:00Z")

</div>

Found the issue. `proxy_set_header` is not inherited if there is any `proxy_set_header` in the current block.

---

<div class="post-metadata">

**Author:** ![buchireddy](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@buchireddy](https://discuss.konghq.com/u/buchireddy)\
**Post date:** [September 16, 2018, 1:42am UTC](https://discuss.konghq.com/t/getting-ip-forward-to-work-with-ip-restriction-plugin-and-proxy-nginx/1740/8 "2018-09-16T01:42:59Z")

</div>

Hi all,  
I am using kong in kubernetes, how to modify the nginx configuration in kubernetes.  
i have to modify x-forwarded setting for getting client ip.  
please let know how to proceed in kubernetes.
