varnish常见问题之HTTP头的用途
精选 翻译fenghao.cn 博主文章分类:linux服务器架设及经验心得
X-Varnish HTTP头的用途?
X-Varnish HTTP头可以让你找到正确的日志记录,比如命中cache,X-Varnish控制当前请求的次数和增加cache中的请求数。它让debugging非常容易。
Varnish支持压缩吗?
这个简单的问题有一个复杂的回答,请看WIKI
我怎么样添加一个HTTP头?
添加一个HTTP头,除非你想要添加一些关于客户端请求的东西,添加HTTP头最好在vcl_fetch中完成,这个方法将处理每个fetched的目标:
sub vcl_fetch {
# Add a unique header containing the cache servers IP address:
remove obj.http.X-Varnish-IP;
set obj.http.X-Varnish-IP = server.ip;
# Another header:
set obj.http.Foo = "bar";
}
我怎么样才能在后端服务器记录客户端的IP地址?
通常我们看见的IP地址是varnish服务器的,怎么样我们才能看见客户端的IP地址呢?
我们需要添加这些IP地址到一个头,然后和请求一起发送给后端服务器,然后配置后端服务器的日志记录这个头信息的内容:
Varnish configuration:
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;
# [...]
}
以apache配置为例,我们拷贝 combined 日志格式,改名为“varnishcombined”,我们在格式中加入varnish定义的头:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined
然后在你的主机配置部分,使用定制的日志格式替换标准的格式:
<VirtualHost *:80>
ServerName www.example.com
# [...]
varnishcombined /var/log/apache2/www.example.com/access.log varnishcombined
# [...]
</VirtualHost>
The [http://www.openinfo.co.uk/apache/index.html mod_extract_forwarded Apache module] might also be useful.
上一篇:varnish常见问题与答案
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
varnish常见问题之config和log
●Configuration 什么是VCL? &nb
职场 休闲 varnish常见问题之配置和日志 -
varnish常见问题与答案
What is varnish? Varnish是一种状态艺
职场 休闲 varnish常见问题和答案