如何设置Varnish日志记录? [英] How to setup Varnish logging?

查看:282
本文介绍了如何设置Varnish日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让Varnish记录请求.我找到了命令varnishlog -a -w /var/log/varnish.log,但是它没有记录任何内容.

I want to get Varnish to log requests. I found the command varnishlog -a -w /var/log/varnish.log, but it does not log anything.

然后我发现Varnish在默认情况下不会写入日志.但是我找不到用于日志记录的配置选项.

Then I found that Varnish does not write to log by default. However I am unable to find configuration options for logging.

推荐答案

如果要以您需要使用varnishncsa的"NCSA通用日志格式" .在CentOS/RedHat上,Varnish RPM软件包包括一个varnishncsa初始化脚本,您可以使用该脚本来开始记录日志.默认情况下,它记录到logfile="/var/log/varnish/varnishncsa.log".

If you want to log HTTP requests in NCSA Common Log Format you need to use varnishncsa. On CentOS/RedHat, the Varnish RPM package includes a varnishncsa init script that you can use to start logging. By default it logs to logfile="/var/log/varnish/varnishncsa.log".

此外,如果您希望通过一次Varnish安装为多个不同的主机提供服务,则还需要在日志中包括主机名.这可以通过/etc/sysconfig/varnishncsa

Additionally if you wish to serve several different hosts through a single Varnish install, you'll want to include the host name in the log as well. This can be accomplished with the following setting in /etc/sysconfig/varnishncsa

DAEMON_OPTS="$DAEMON_OPTS -F '%{Host}i %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"'"

请注意,Anshu链接中描述的方法仅记录由Varnish传递到后端服务器的请求. 缓存命中请求将永远不会被记录(在Varnish 5.0之前-参见下文).因此,以这种方式收集的HTTPD日志不能用于统计分析.

Please note that the method described in the link by Anshu only logs the requests that are passed through by Varnish to the backend servers. Cache hit requests will never be recorded (before Varnish 5.0 - see below). Therefore the HTTPD logs gathered this way cannot be used for statistical analysis.

更新:正如@VikrantPogula所述,从Varnish 5.0开始,所有客户端请求均已记录-包括缓存命中.这是默认行为,可以使用-c开关明确打开.

Update: As @VikrantPogula mentioned, as of Varnish 5.0 all client requests are logged - including cache hits. This is the default behavior, and can be switched on explicitly using the -c switch.

这篇关于如何设置Varnish日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆