Open waruboy opened 10 years ago
We tend to run Rails apps on Heroku, in which case the routing layer acts as an HTTP proxy and request.ip is the IP of the proxy, not the user. The correct approach would be to use 'X-Forwarded-For' only if it is present:
request.env.fetch('HTTP_X_FORWARDED_FOR', request.remote_ip)
^^ what this guy said
@werkshy @danielschwartz I too faced similar situation using nginx and phusion passenger and had to tweak that piece of code. Would be great if this is changed in the code or add some reference in the README regarding this.
I've made pull request https://github.com/harrystech/prelaunchr/pull/43 with solution.
In the users_controller, you use request.env['HTTP_X_FORWARDED_FOR'] to detect the visitor IP. In my case, I'm using a standalone phusion passenger setup, and found it not working.
I change it to request.remote_ip, then it works. Later, I change my setup using nginx in front of phusion passenger. Still works.
Is there any reason you use request.env['HTTP_X_FORWARDED_FOR'] instead of request.remote_ip ?