我在CentOS 5.8上使用HAProxy 1.3.26来代理所有请求到一个专用服务器。 我使用HAProxy只是将HTTP和HTTPS代理到一台服务器,所以没有负载平衡。
我的haproxy.cfg相当简单:
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice maxconn 4096 user haproxy group haproxy daemon defaults log global option dontlognull option httpclose option forwardfor clitimeout 60000 srvtimeout 60000 contimeout 5000 retries 3 option redispatch listen http 192.168.0.1:80 mode tcp option tcplog maxconn 10000 server web01 192.0.1.13:80 maxconn 5000 listen https 192.168.0.1:443 mode tcp maxconn 10000 server web01 192.0.1.13:443 maxconn 5000
哪里:
192.168.0.1 - server where HAProxy is installed 192.0.1.13 - server to which HTTP requests are forwarded
我希望在我的Apache 2.2.3访问日志中看到客户的IP地址。 此选项通常通过添加HTTP X-Forwarded-For标头然后在Web服务器日志中读取来实现。 所以,我在httpd.conf中添加了以下几行:
LogFormat "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"" combined LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"" combined_forwarded SetEnvIfNoCase X-Forwarded-For "." from_proxy=1 CustomLog logs/access_log combined env=!from_proxy CustomLog logs/access_log combined_forwarded env=from_proxy
问题是只有logging的IP地址是192.168.0.1 (HAProxy服务器)。 我已经尝试了不同的configuration,阅读文档,谷歌search,但仍然不明白为什么客户端的IP没有logging。
我觉得我错过了简单的东西,因为configuration非常简单。 如有可能请帮助更正configuration。
感谢您的任何帮助。
请不要忘记,这对https代理不起作用,因为haproxy将无法破解encryption会话的内容。 你可能也想检查Apache的mod_rpaf模块,这样做更容易。