views:

355

answers:

2

I have an application running with debug=True on a remote host somewhere. Now somehow every time I access REMOTE_ADDR it returns 127.0.0.1 no matter where the request is from.

I'm not sure where to start and why this is happening.

+4  A: 

Do you have any kind of proxy, gateway, or load balancer running on that remote host? That's the sort of thing that would cause connections to appear to be from 127.0.0.1 (because that's where the immediate connection is from, as far as the web server is concerned).

Greg Hewgill
To further this, you can check if the X-Forwarded-For http header is present, this should contain the ip you want.
Lepidosteus
You should be careful relying on X-Forwarded-For, it's easily spoofed. In fact Django used to have a middleware that automatically set REMOTE_ADDR based on X-Forwarded-For, but removed it because it tempted people to rely on the unreliable.
Carl Meyer
A: 

If you are behind a proxy and running apache as the webserver you could use mod_rpaf. The proxy only needs to send X-Forwarded-For or X-Real-IP headers.

http://stderr.net/apache/rpaf/

bjunix