B3-从http头中找到X-Forwarded-For发来的客户端ip 地址
拓扑
haproxy (10.0.100.82) ----> 动态 php_server (10.0.100.70)
|静态
squid_server (10.0.100.73)
|
PIC server (nfs/nginx 图片服务器) (10.0.100.71)
squid access.log 日志留下的是 haproxy 的ip 地址。
10.0.100.82 - - [15/Jun/2012:11:17:20 +0800] "GET http://monitor.test.com/cacti/images/shadow_gray.gif HTTP/1.1" 304 283 "http://monitor.test.com/cacti/graph.php?action=view&local_graph_id=62&rra_id=all" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0" TCP_IMS_HIT:NONE
解决方法
1 首先编译squid时 请使用 -–enable-follow-x-forwarded-for 参数
2 编辑 squid.conf配置文件,定义squid 日志格式,注意红色字
logformat combined %{X-Forwarded-For}>h %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
3 squid 重新载入配置
/usr/local/squid/sbin/squid -k reconfigure
更改完成后的squid 日志
192.168.4.164 - - [15/Jun/2012:11:31:30 +0800] "GET http://monitor.test.com/cacti/images/graph_properties.gif HTTP/1.1" 304 284 "http://monitor.test.com/cacti/graph_view.php?action=tree&tree_id=3&leaf_id=13" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0" TCP_IMS_HIT:NONE
更多欢迎到此讨论:
37275208
本文转自 dongnan 51CTO博客,原文链接:http://blog.51cto.com/dngood/899459
\