Skip to content

Instantly share code, notes, and snippets.

@bzdk
Created October 14, 2013 14:16
Show Gist options
  • Save bzdk/6976370 to your computer and use it in GitHub Desktop.
Save bzdk/6976370 to your computer and use it in GitHub Desktop.
XForwardedForMiddleware for Django work with Nginx
class XForwardedForMiddleware(object):
def process_request(self, request):
if "HTTP_X_FORWARDED_FOR" in request.META:
ip = request.META["HTTP_X_FORWARDED_FOR"]
if ip.startswith('::ffff:'):
ip = ip[len('::ffff:'):]
request.META["REMOTE_ADDR"] = ip
request.META["REMOTE_HOST"] = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment