When getting the IP with request.META['REMOTE_ADDR']
code. This works fine on the local system but when hosted on a web server the ip got is 127.0.0.1 - How can this be resolved?
views:
192answers:
2
+7
A:
Your web server is probably behind a load balancer. You can try using request.META['HTTP_X_FORWARDED_FOR'].
Or better, look at the django book, chapter 15 - What’s Middleware? and Reverse Proxy Support (X-Forwarded-For Middleware) sections.
Ofri Raviv
2010-01-27 06:17:52
Note that the X-Forwarded-For middleware has been deprecated/removed from recent Django versions, as it was decided that it might give developers a false sense that the X-Forwarded-For header can actually be relied upon (which it can't). Easy enough to write your own; just be aware it can easily be spoofed.
Carl Meyer
2010-01-30 15:29:01
+1
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.
bjunix
2010-02-23 00:22:20