mod_extforward:逆向代理/负载均衡器背后的Lighttpd日志客户端真实IP
时间:2020-01-09 10:42:46 来源:igfitidea点击:
我有在基于Nginx的反向代理/负载均衡器后面设置了5个lighttpd Web服务器,以为繁忙的电子商务网站分配负载。
但是,所有Web服务器节点都将我的负载均衡器的两个IP地址放在访问日志文件中。
如何强制lighttpd记录访问我们网站的所有客户端计算机的真实IP(公共IP)地址?
您需要使用Lighttpd下的mod_extforward从X-Forwarded-For或者X-Real-IP标头中提取并记录客户端真实IP,该标头由反向代理服务器(例如Nginx或者Squid代理服务器)添加。
配置
编辑lighttpd.conf文件,执行:
# vi /etc/lighttpd/lighttpd.conf
"警告!" mod_extforward包含在lighttpd 1.4.14及更高版本中。
在server.modules指令的末尾添加mod_extforward(顺序很重要):
server.modules = (
"mod_redirect",
"mod_alias",
"mod_rewrite",
"mod_expire",
"mod_access",
"mod_auth",
"mod_status",
"mod_fastcgi",
"mod_secdownload",
"mod_accesslog",
"mod_compress",
### add mod_extforward ####
"mod_extforward"
)
添加您的代理服务器/反向代理负载平衡器IP
添加基于nginx的反向代理ip(LB IP),例如10.10.28.5和10.10.28.6:
extforward.forwarder = (
"10.10.28.5" - "trust",
"10.10.28.6" - "trust"
)
保存并关闭文件。
如何设置客户端自定义IP标头?
您还可以使用以下语法设置标头来搜索以查找客户端的原始IP地址:
extforward.headers = ("X-Cluster-Client-Ip")
或者
extforward.headers = ("X-Real-Ip")
重新启动Lighttpd
最后,重新启动lighttpd Web服务器,执行:
# service lighttpd restart
您可以使用tail命令查看访问日志:
# tail -f /var/log/lighttpd/access.log

