首页 > Web开发 > 详细

apache关于记录真实客户端ip和不记录健康检查日志

时间:2014-12-18 19:03:22      阅读:364      评论:0      收藏:0      [点我收藏+]

由于负载均衡会转发客户端的请求到web服务器,所以web服务往往记录的是负载均衡的IP,现在可以通过下面的配置,让apache记录真实客户端IP

语法

#LogFormat  “\”%{X-Forwarded-For}i\”%l %t \"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\"" combined

普通日志和记录客户端IP的apache日志比较

#LogFormat "%h %l %u %t \"%r\" %>s%b \"%{Referer}i\" \"%{User-Agent}i\"" combined

#LogFormat “\”%{X-Forwarded-For}i\” %l %t \"%r\" %>s %b\"%{Referer}i\" \"%{User-Agent}i\"" combined

统计日志中客户端访问数量

cut -d " " -f1  www.sr1.com_access_log | sort |uniq -c|sort-rn -k1

结果:

 4799 192.168.254.251

   1335 192.168.254.250

      2 192.168.254.191

apache不记录健康检查日志

由于负载均衡的健康检查会造成apache的访问日志备大量写入,使得访问量无法统计,使用下面的方法可以让apache不再记录负载均衡的健康检查日志

配置(checkstatus.html):

SetEnvIfRequest_URI "^/checkstatus.html" dontlog

ErrorLog"logs/error_log"

LogLevel warn

CustomLog"logs/access_log" combined env=!dontlog

虚拟主机不记录健康检查日志(checkstatus.html):

<VirtualHost*:80>

    DocumentRoot"/usr/local/httpd-2.2.9/htdocs/sr1/"

    ServerName www.sr1.com

    ServerAlias www.sr1.com

SetEnvIf Request_URI "^/checkstatus.html " dontlog

    ErrorLog"logs/www.sr1.com_error_log"

   CustomLog"logs/www.sr1.com_access_log" haproxy env=!dontlog

</VirtualHost>

 

 


本文出自 “Study-Everyday” 博客,请务必保留此出处http://studys.blog.51cto.com/9736817/1591441

apache关于记录真实客户端ip和不记录健康检查日志

原文:http://studys.blog.51cto.com/9736817/1591441

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!