My server doesn't have a public IP address, so I don't know how to get the real client's IP address.
This is my nginx's 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 app's controller both request.ip
and request.remote_ip
return my server's gateway address.
How can i get the real IP of client?
How to get X-Forwarded-For value from Rails request?
remote_ip checks all IPs present in the HTTP header, looking for fields generally used by firewalls, load balancers, or proxies, such as HTTP_X_FORWARDED_FOR, and make a guess to return what seems to be the correct visitor's IP address. From now, if you connect to your server, you will see your real IP address.
Rails was supposed to be doing it automatically for us, but it seems to be broken with current 3.x
I'm using this:
def ip() request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip end
You should get the header value X-forwarded-for
http://en.wikipedia.org/wiki/X-Forwarded-For
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With