我在当前的设置中使用loadbalancer,请求来自IP 10.71.128.13 。
我使用Nginx作为Gunicorn后端的前端。 我想获得访问者的真实IP地址并logging它(而不是负载均衡IP)。
我的nginx.conf:
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # GET REAL IP set_real_ip_from 10.71.128.12; set_real_ip_from 10.71.128.13; set_real_ip_from 10.71.128.14; real_ip_header X-Forwarded-For;
我的服务器块'example.conf'
# HTTPS server { etc.... location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; proxy_redirect off; proxy_buffering on; } }
日志条目示例:
10.71.128.13 - - [10/Jun/2014:13:27:58 +0100] "POST /example/ HTTP/1.1" 200 25 "https://example.com/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
可悲的是,这种configuration只是返回负载平衡IP,而不是访问者的IP地址…任何人都可以帮忙吗?
谢谢
当您使用SSL传递负载平衡时,代理无法添加所需的标题,因此您永远不会知道发起的IP