Get real client IP with Rails and Nginx?

My server does not have a public IP address, so I do not know how to get the real IP address of the client.

This is my nginx configuration:

location / { proxy_pass http://domain1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } 

In my Rails application controller, both request.ip and request.remote_ip return the server gateway address.

How can I get the real IP address of the client?

How to get X-Forwarded-For value from a Rails request?

+7
source share
2 answers

You should get the value of the X-forwarded-for header

http://en.wikipedia.org/wiki/X-Forwarded-For

+6
source

Rails should have done this automatically for us, but it seems to be broken with the current 3.x

I use this:

 def ip() request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip end 
+18
source

All Articles