1

When using https, the request.remote_ip returns 127.0.0.1. This prevents geocode lookup.

Is there a way to get the correct remote IP?

I have seen a few possible workarounds:

request.env['REMOTE_ADDR'] 
request.env['HTTP_X_FORWARDED_FOR']

which return 10.102.1.1

request.env[‘HTTP_X_REAL_IP’] 

which returns ""

Will
  • 4,498
  • 2
  • 38
  • 65
  • possible duplicate of [Get real IP address in local Rails development environment](http://stackoverflow.com/questions/3887943/get-real-ip-address-in-local-rails-development-environment) – jww Jul 12 '14 at 08:58
  • No. That question was about a local dev environment not returning remote ip, which is common & easy to work around. this is about remote_ip not being returned when the request is https – Will Jul 12 '14 at 09:08
  • Try this one: [Get Actual Remote IP in Rails?](http://stackoverflow.com/questions/8090692/get-actual-remote-ip-in-rails). – jww Jul 12 '14 at 09:18
  • Not sure if this is related, but in your example looking at HTTP_X_REAL_IP is using curly/fancy quotes vs proper single quotes. – Brian Jul 12 '14 at 15:35
  • @Brian - good spot, but alas no, i'm using correct single quotes in the real code. just a copy paste error thing here. – Will Jul 13 '14 at 02:11
  • @jww thanks mate but thats the local environment thing again. To be clear, this is not an issue on the development machine. its on the production server. The questions you are linking to are completely unrelated. – Will Jul 13 '14 at 02:14

2 Answers2

0

It turns out this is a limitation of the way the server at ninefold is set up.

"Since our Rails stack is Apache Passenger, the client side IP headers are actually stripped off when they pass through the HA Proxy load balancer. In the CItrix implementation of this service, we are unable to pass those headers through to the rails app. At this stage its not possible to access the remote user's IP address."

Will
  • 4,498
  • 2
  • 38
  • 65
0

As a possible work around, you could use a service like Fastly to do your load balancing, then point it directly at your app servers' IPs to bypass HAProxy on Ninefold. You'd get a nice, fast CDN in the process too.

Ryan Clark
  • 764
  • 1
  • 8
  • 29