使用Haproxy时apache日志的配置方法
在使用haproxy作反向代理时,apache日志配置中%h抓取的是haproxy主机Ip,而非用户Ip地址,如果想让apache记录用户ip,只需把%h改成{X-Forwarded-For}i 即可
后端apache日志处理
配置httpd.conf
<IfModule log_config_module>
#
# Thefollowing directives define some format nicknames for usewith
# aCustomLog directive (see below).
#
#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
#LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat"%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b"common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
#LogFormat "%h %l %u %t \"%r\" %>s %b\"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s%b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>........
其它的不变,保存后重启apache