PS:今天一同事问我怎么用haproxy作前端反向代理后,Apache日志记录的IP是haproxy主机的IP,而不是用户客户端的IP。其实如果想让Apache记录用户客户端IP,只需把日志配置里的h改成{X-Forwarded-For}i就可以。
vim httpd.conf
找出如下的日志配置:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent
保存,重启apache就ok。