How do I pass the remote (users) IP from nginx to Rails hosted on google container engine?

7/19/2016

I'm running passenger on nginx and have a rails app server. I'm unable to get the user's remote IP.. how can I get the User's IP?

I use a nginx.conf.erb which I can modify if needed..

The problem (I think) arises in google container engine which creates a load balancer in front of my app.. making request.remote_ip only get a local kubernetes cluster-ip rather than the remote ip..

-- sambehera
google-kubernetes-engine
ip-address
kubernetes
nginx
ruby-on-rails

1 Answer

7/19/2016

That should be pretty simple, infact you don't have to pass it from Nginx it always comes to rails as headers. You can access it as follows,

request.remote_ip
-- Pragash
Source: StackOverflow