如何设置清漆缓存控制标头 [英] How to Set Varnish Cache-Control Headers

查看:179
本文介绍了如何设置清漆缓存控制标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以建议让Varnish发送缓存控制标头的正确方法。目前,我的配置是向客户端发送Cache-Control:no-cache

I am hoping someone can advise on the proper method for getting Varnish to send cache-control headers. Currently, my configuration is sending "Cache-Control: no-cache" to clients.

提前感谢任何可能提供帮助的人......

Thanks in advance to anyone who might be able to help...

推荐答案

你的后端正在向Varnish发送Cache-Control:no-cache,这意味着两件事:

Your back-end is sending "Cache-Control: no-cache" to Varnish which implies two things:


  • Varnish will不将响应存储在缓存中(因此下一次查找将失败)

  • 您的客户端(浏览器和中间代理)不会缓存响应(并反复请求它们)。

解决方案很简单:从后端获取响应后(以及在将它们存储在缓存中之前)删除缓存控制头。

The solution is simple: remove the cache-control headers after fetching the response from the back-end (and before storing them in the cache).

在你的vcl文件中执行:

In your vcl file do:

sub vcl_fetch {
  remove beresp.http.Cache-Control;
  set beresp.http.Cache-Control = "public";
}

您可以选择仅对某些网址执行此操作(将其包装在(如果req.url~)逻辑)并且做更多高级的东西。

You can choose to only do this for certain urls (wrap it in ( if req.url ~ "" ) logic) and do way more advanced stuff.

这篇关于如何设置清漆缓存控制标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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