我已经使用 Apache 配置了 Varnish 3,并且它运行得很好。但是我无法获取 Apache 日志中记录的客户端 IP。我在谷歌上尝试了一些解决方案,但没有成功。现在我的 Apache 访问日志文件正在记录服务器 IP 而不是客户端 IP 地址。
以下是我的配置供您考虑:
Varnish VCL:(/etc/varnish/default.vlc):http://pastebin.com/PuBqZ6fx
Apache 配置
/etc/httpd/conf/httpd.conf
LogFormat "%{X-Forwarded-For}i %l %u %t\"%r\"%>s %b\"%{Referer}i\"\"%{User-Agent}i\""Varnish 组合
Apache 虚拟主机
...... 其他的东西 ..... 错误日志日志/fr-error-log CustomLog 日志/fr-custom-log varnishcombined ...... 其他的东西 .....
注意:安装的 Varnish 版本是 varnish-3.0.2-1.el5.x86_64
谢谢。 拉希尔
最佳答案
我认为你的pastebin示例中有一个有效的配置,这实际上应该可以解决问题:
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
在您的 vcl_recv{} 中。
关于Varnish 客户端 IP 未记录在 Apache 日志中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10024877/