Browse Source

HUE-5281 [core] Log real user real ip when using a load balancer

https://github.com/cloudera/hue/pull/443

if using nginx proxy, we should use HTTP_X_FORWARDED_FOR to get client real ip;
todaychi 9 years ago
parent
commit
f52b2df
1 changed files with 4 additions and 1 deletions
  1. 4 1
      desktop/core/src/desktop/log/access.py

+ 4 - 1
desktop/core/src/desktop/log/access.py

@@ -70,7 +70,10 @@ class AccessInfo(dict):
   """
   def __init__(self, request):
     self['username'] = request.user.username or '-anon-'
-    self['remote_ip'] = request.META.get('REMOTE_ADDR', '-')
+    if request.META.has_key('HTTP_X_FORWARDED_FOR'):
+      self['remote_ip'] = request.META.get('HTTP_X_FORWARDED_FOR', '-')
+    else:
+      self['remote_ip'] = request.META.get('REMOTE_ADDR', '-')
     self['method'] = request.method
     self['path'] = request.path
     self['proto'] = request.META.get('SERVER_PROTOCOL', '-')