Squid 升级到 3.0 以及传递客户端 IP 地址给 Apache
- Image via Wikipedia
重新编译 Squid ,原来2.6 的一些参数要修改的:
关键字 protocol 变成了 proto
acl myhttp proto HTTP
no_cache 变成了 cache:
cache deny getip
加入 forwarded_for on 到 squid.conf ,可以把 客户端 IP 地址传递给后台的 Apache ,方法是采用 X-FORWARDED-FOR 的 HTTP 头。
用 PHP 抓取:
$ip = getenv(‘REMOTE_ADDR’);
if ( $ip == “127.0.0.1” )? $ip=getenv(‘HTTP_X_FORWARDED_FOR’);
Apache 日志显示,修改日志记录方式为:
LogFormat ‘%{X-Forwarded-For}i %v %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”‘ cached
检查客户端 IP 地址的例子:? http://myip.freelamp.com/