198211401182 发表于 2015-11-20 12:21:13

使用Haproxy时apache日志的配置方法

使用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&quot;%h %l %u %t \&quot;%r\&quot; %>s %b \&quot;%{Referer}i\&quot;\&quot;%{User-Agent}i\&quot;&quot; combined
LogFormat&quot;%{X-Forwarded-For}i %l %u %t \&quot;%r\&quot; %>s %b\&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; combined
#LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %>s %b&quot; common
LogFormat&quot;%{X-Forwarded-For}i %l %u %t \&quot;%r\&quot; %>s %b&quot;common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
#LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %>s %b\&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot; %I %O&quot; combinedio
LogFormat &quot;%{X-Forwarded-For}i %l %u %t \&quot;%r\&quot; %>s%b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot; %I %O&quot; combinedio
</IfModule>........
  其它的不变,保存后重启apache
页: [1]
查看完整版本: 使用Haproxy时apache日志的配置方法