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: , ,

One Response to “Rails remote IP address from behind a proxy”

  1. Birm Says:

    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.

Leave a Reply

© 2008 Josh Rendek.