浏览代码

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 年之前
父节点
当前提交
f52b2df
共有 1 个文件被更改,包括 4 次插入1 次删除
  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', '-')