varnish - 如何检查 Varnish 缓存是否正常工作?

标签 varnish

我在 Nginx 上运行的 Wordpress 网站上使用 Varnish Cache。它的配置方式如 this blog 中提到的。 。它正在工作,但我不确定它是否确实从缓存中提供内容。

如何确定?有人可以指导我吗?我是 Varnish 缓存的新手。

最佳答案

默认情况下,Varnish 会在其处理的任何请求的响应中添加 header 。您可以使用 Firebug 等浏览器工具或 curlGET 等 CLI 工具查看响应 header 。这是一个 GET 示例:

sudo apt-get install libwww-perl && GET -Used http://localhost:6081/index.html

要查找的两个 header 是X-VarnishAgeX-Varnish 中将包含一两个数字,数字本身并不重要,但它们涉及请求。如果请求失败,Varnish 会从后端获取页面,并且响应中的 X-Varnish header 包含当前请求的一个数字:

X-Varnish: 107856168

下次请求同一页面时,可能会导致命中。如果是,Varnish 会从缓存中获取页面,并添加原始请求中的数字:

X-Varnish: 107856170 107856168

Age header 表示缓存副本已有多少秒了。如果未命中,则为 0;如果命中,则 > 0。

请注意,后端可以设置年龄 header ,这使其看起来像是错误命中,并且堆叠的 Varnish 可能会在 X-Varnish header 中产生错误的未命中。为了在调试时绝对确定,您可以在 VCL hit 和 miss 函数中添加自己的 header 。请参阅此页面了解说明 https://www.varnish-software.com/static/book/VCL_functions.html 。作为 Varnish 的新手,X-Varnish 和 Age header 很可能就是您所需要的。

关于varnish - 如何检查 Varnish 缓存是否正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20747210/

相关文章:

caching - Varnish 3.0 返回 503 错误

caching - Varnish 禁令永远留在禁酒令中

cluster-computing - 在 Varnish 3.0.3 集群上清除

nginx - 如何让 Nginx 不服务于直接请求?

Magento 2 + WHM + SSL + Varnish 配置问题

ssl - 挂接服务无法启动 |搭便车 1.5.2-1 | Ubuntu 20.04.1 LTS

varnish - 为什么 Varnish 禁令要求不删除/无效缓存的数据?

google-chrome - Chrome 不是由 SSL 提供的缓存内容

regex - 使用regsub捕获查询字符串左侧的值

python - 为什么 Django 不在 Varnish 代理后面生成 CSRF 或 session Cookie?