# Last IP address and action\_dispatch.trusted\_proxies

**URL:** <https://meta.discourse.org/t/last-ip-address-and-action-dispatch-trusted-proxies/50098>\
**Category:** Product Support\
**Created:** [13 سبتمبر 2016، 5:50م UTC](https://meta.discourse.org/t/last-ip-address-and-action-dispatch-trusted-proxies/50098 "2016-09-13T17:50:59Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![dorian\_kind](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dorian_kind/32/115240_2.png) [@dorian\_kind](https://meta.discourse.org/u/dorian_kind)\
**Post date:** [13 سبتمبر 2016، 5:50م UTC](https://meta.discourse.org/t/last-ip-address-and-action-dispatch-trusted-proxies/50098/1 "2016-09-13T17:50:59Z")

</div>

I’m experiencing the problem that all of our users have `127.0.0.1` as last IP address. This issue was previously discussed [here](https://www.google.ch/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwi4quut8IzPAhXEPRQKHaikBcMQFggcMAA&url=https%3A%2F%2Fmeta.discourse.org%2Ft%2Fall-of-my-internal-users-show-as-coming-from-127-0-0-1%2F6607&usg=AFQjCNFaUe8nR4por5HWC-Y3mpJcPx-mpA&sig2=9a9nKZ-eVVr0pd_7qBgG6g&bvm=bv.132479545,d.bGg&cad=rja), [here](https://www.google.ch/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwi4quut8IzPAhXEPRQKHaikBcMQFggiMAE&url=https%3A%2F%2Fmeta.discourse.org%2Ft%2Flast-ip-address-always-127-0-0-1%2F31894&usg=AFQjCNEleqtpimlM9pIJZozZBksEE6fhww&sig2=xNyHkQzq_392qcQwwQL6lA&bvm=bv.132479545,d.bGg&cad=rja) and [here](https://www.google.ch/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0ahUKEwi4quut8IzPAhXEPRQKHaikBcMQFggoMAI&url=https%3A%2F%2Fmeta.discourse.org%2Ft%2Fwhen-all-users-come-from-127-0-0-1-new-registrations-are-blocked%2F29533&usg=AFQjCNFyObczMTx30OCzlO0iJo1my8wRZw&sig2=7HX71niLWrMMee_TWl_54Q&bvm=bv.132479545,d.bGg&cad=rja), and all of these threads contain valuable input, but I still cannot get it to work.

Our setup is an internal Discourse installation (Docker) behind an internal SSL-proxy. All our users also access Discourse from our internal network (directly or via VPN).

When I `tcpdump` a packet from Discourse’s `nginx` to the Rails app, I see the following:

> ```
> GET / HTTP/1.0
> Host: <our discourse host>
> X-Real-IP: 10.10.2.3
> X-Forwarded-For: 10.10.0.89, 10.10.2.3
> X-Forwarded-Proto: https
> Connection: close
> Cache-Control: max-age=0
> 
> ```

This is correct as the SSL proxy is `10.10.2.3` and the client’s IP address is `10.10.0.89`.

Now the way I understand that the responsible middleware in Rails works is that it removes all IPs from the `X-Forwarded-For` list that seem to be proxies. The default list `TRUSTED_PROXIES` includes all private IP network ranges, thus leaving no IP left and going with `127.0.0.1` as the default (because of `REMOTE_ADDR` coming from Discourse’s `nginx`).

I have modified `config/application.rb` to include

> ```
> config.action_dispatch.trusted_proxies = %w(127.0.0.1/32 10.10.2.3/32).map { |proxy| IPAddr.new(proxy) }
> 
> ```

and restarted the docker container. This seems to have the desired effect at first. When I run a Rails console inside the app, I see the following:

> ```
> rails c production
> Loading production environment (Rails 4.2.7)
> irb(main):001:0> app.get '/'
> Started GET "/" for 127.0.0.1 at 2016-09-13 17:45:09 +0000
> Processing by CategoriesController#index as HTML
> Redirected to http://www.example.com/login
> Filter chain halted as :redirect_to_login_if_required rendered or redirected
> Completed 302 Found in 68ms (ActiveRecord: 13.0ms)
> => 302
> irb(main):002:0> app.request.env['action_dispatch.remote_ip'].instance_variable_get :@proxies
> => [#<IPAddr: IPv4:127.0.0.1/255.255.255.255>, #<IPAddr: IPv4:10.10.2.3/255.255.255.255>]
> irb(main):003:0> 
> 
> ```

So it seems that the `RemoteIp` middleware now uses the right IP addresses as a proxy list.

**However** , I still only see `127.0.0.1` as last IP address for our users. Don’t really know what else to do—if anyone can shed some light on the behavior, I’d appreciate it.

---

_[View the full topic](https://meta.discourse.org/t/last-ip-address-and-action-dispatch-trusted-proxies/50098)._
