Rails remote IP address from behind a proxy
Since I have a cluster of 3 mongrels running behind lighttpd the usualy request.env['REMOTE_ADDR'] wasn’t working …
what ended up working was request.env['HTTP_X_FORWARDED_FOR'] to get the users IP
Tags: rails, ruby, ruby on rails
Apps

Twitter
August 18th, 2009 at 12:10 am
This works perfectly for me on Slicehost. One small change I made to make localhost a bit more friendly was:
request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip()
Otherwise, localhost returns null.