Rah*_*lia 6 varnish varnish-vcl
我用Apache配置了Varnish 3,它运行得很好.但是我无法在Apache日志中记录客户端IP.我试了几个解决方案,没有运气.现在我的Apache访问日志文件正在记录服务器IP而不是客户端IP地址.
以下是我的配置供您考虑:
光油VCL:(/etc/varnish/default.vlc):http://pastebin.com/PuBqZ6fx
/etc/httpd/conf/httpd.conf中
LogFormat"%{X-Forwarded-For} i%l%u%t \"%r \"%> s%b \"%{Referer} i \"\"%{User-Agent} i \""varnishcombined
......其他东西...... ErrorLog日志/ fr-error-log CustomLog日志/ fr-custom-log varnishcombined ......其他东西......
注意:安装的Varnish版本是varnish-3.0.2-1.el5.x86_64
谢谢.Raheel
Moj*_*jah 12
我认为你的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;
}
}
Run Code Online (Sandbox Code Playgroud)
在你的vcl_recv {}中.
chm*_*mac 10
正如评论中提到的OP,解决方案是Apache模块.Varnish X-Forwarded-For默认添加标题.
然后像mod_rpaf(Apache 2.2)或mod_remoteip(Apache 2.4)这样的apache模块将remote_ip值设置为X-Forwarded-For标头传入的值.
与仅将X-Forwarded-For标头的值记录到apache日志中相比,这提供了更强大的解决方案.例如,它允许您通过Varnish或直接访问2个IP上的同一站点,并且站点按照您的预期运行并正确记录.
将此行添加到您的vcl
sub vcl_recv {
# Add a unique header containing the client address
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
}
Run Code Online (Sandbox Code Playgroud)
然后更改apache的logformat
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined
Run Code Online (Sandbox Code Playgroud)
现在在您的Virtualhost中
<VirtualHost *:8080>
ServerName www.abc.com
CustomLog /var/log/httpd/www.abc.com/access.log varnishcombined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)