我是 Varnish 的新手,我在 Debian Wheezy 上运行 v4.0。
我想在 4 周的缓存中设置默认 TTL(非常静态的内容)。
通过阅读文档,我认为答案是default_ttl在我的 VCL 文件中的某处设置一个选项。我搜索了文档,但只能找到一个参考。
我发现了这个问题,但我认为答案一定是过时的,因为它对我不起作用。
有人可以澄清如何在 Varnish 4.0 中做到这一点吗?
更新:这是我的配置文件(Varnish 4.0 附带的默认文件,除了我将后端指向本地主机):
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_backend_fetch {
set obj.ttl = 4w;
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}
sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}
Run Code Online (Sandbox Code Playgroud)
default_ttl是一个运行时参数。启动时就可以设置varnishd。
默认生存时间
单位:秒 默认值:120.000 最小值:0.000 标志:如果后端和 VCL 代码都没有分配 TTL,则分配给对象的 TTL。
您可以通过 2 种不同的方式设置此参数。无论您选择哪种方式都会做完全相同的事情。
您可以使用快捷方式-t
-t ttl 指定缓存文档的硬性最短生存时间。这是指定 default_ttl 运行时参数的快捷方式。
或者,您可以使用-p param=value
例如,您可以像这样启动 varnishd:
使用快捷方式:
varnishd -a 127.0.0.1:8081 -T 127.0.0.1 -t 2419200
使用更长的形式:
varnishd -a 127.0.0.1:8081 -T 127.0.0.1 -p default_ttl=2419200
数字 2419200 是以秒为单位的 4 周。
| 归档时间: |
|
| 查看次数: |
5790 次 |
| 最近记录: |