Using Django, why would REMOTE_ADDR return 127.0.0.1 on a web server?

django, python

Solution

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.

Problem

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?

Original source