我刚开始使用清漆。我安装了它,我想我正确地配置了它。为了测试这就是我所做的
我创建了一个只有字符串" test“的测试页面。我转到页面上,它有以下标题:
Accept-Ranges:bytes
Age:0
Cache-Control:max-age=120
Connection:keep-alive
Content-Length:6
Content-Type:text/html; charset=UTF-8
Date:Tue, 12 May 2015 19:35:34 GMT
Expires:Tue, 12 May 2015 19:37:34 GMT
Server:Apache/2.2.15 (CentOS)
Via:1.1 varnish-v4
X-Powered-By:PHP/5.3.3
X-Varnish:32829我将文件中的文本更改为"test2“,然后转到页面,它显示"test2”。我认为它应该显示“测试”,如果它是正确的缓存。
我没有准备饼干什么的,就这样。我的vcl非常简单:
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
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.
#This will set up "grace mode".
set beresp.ttl = 10s;
set beresp.grace = 1h;
}
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.
}有什么想法吗?谢谢
发布于 2015-05-13 10:39:48
在您的请求中发送cookie的可能性很大。清漆不缓存任何有饼干的东西。这是来自清漆4的builtin.vcl的:
47 subvcl_recv{ 48 if (req.method == "PRI") { 49 /*我们不支持SPDY或HTTP/2.0 */ 50返回(synth(405));51 } 52 if (req.method != "GET“& 53 req.method != "HEAD”& 54 req.method != "PUT“& 55 req.method != "POST”& 56 req.method !=“跟踪”& 57 req.method != "OPTIONS“& 58 req.method !=”删除“){ 59/*非Non 2616或连接,这是奇怪的。*/ 60返回(管道);61 } 62 63 if (req.method != " GET“& req.method != " HEAD ") { 64 /*我们只处理GET和HEAD默认*/ 65返回(pass);66 } 67 if (req.http.Authorization欧元/ req.http.Cookie) { 68 /*在默认情况下不可缓存*/ 69返回(pass);70 } 71返回(哈希);72 }
您需要删除VCL中不需要的cookie,如这个例子来自“清漆”网站所示
从后端(针对特定路径)删除Set-Cookie,在本例中,我们将删除预定义路径下对象的Cookie头和Set-Cookie头。对于图像和类似的静态内容来说,这是相当常见的。子vcl_recv { if (req.url ~“^/映像”){ unset req.http.cookie;} sub vcl_backend_response { if (req.url ~“^/vcl_backend_response”){ unset beresp.http.set-cookie;}
如果您使用curl -i URL进行测试,您将不会发送任何cookie,如果您在超过一秒钟后重复该测试,您将得到一个大于0的Age标头。
发布于 2015-05-13 10:28:51
我不确定你是否正确地设置了恩典模式。清漆书似乎表明您应该在vcl_fetch和vcl_recv中设置其中的一些内容。
(我不熟悉清漆,但我希望很快就会熟悉)。
核心优雅机制一个优雅对象是一个已经过期的对象,但仍然保持在缓存grace模式中。当Varnish使用一个优雅的对象时,有不止一种方式Varnish可以最终使用一个优雅对象。req.grace定义了一个对象可以延迟多长时间才能仍然认为它为grace模式。beresp.grace根据后端的状态定义beresp.ttl时间清漆将保留一个req.grace经常在vcl_recv中被修改的对象的时间。当Varnish处于优雅模式时,它使用的对象对于TTL来说已经过期了。有几个原因可能会发生,其中之一是如果后端被健康调查标记为坏的话。为了使Varnish能够使用一个优雅的对象,需要发生两件事:对象仍然需要保持在周围。这受到beresp.grace in vcl_fetch的影响。VCL必须允许Varnish使用与周围的对象一样过期的对象。这受到req.grace in vcl_recv的影响。在设置grace时,您需要同时修改vcl_recv和vcl_fetch,以便有效地使用grace。使用grace的典型方法是在TTL之后的几个小时内存储对象,但只在TTL之后几秒钟使用它,除非后端生病。稍后我们将更多地讨论健康检查,但就目前而言,下面的VCL可以说明一个正常的设置:subvcl_recv{ if (req.backend.healthy) { set req.grace =30;} else { set req.grace = 24h;} sub vcl_fetch { set beresp.grace =24小时;
发布于 2015-05-13 07:56:31
检查Apache将哪些标头发送到Varnish。您还可以显式地设置内容的TTL (清漆)。
https://serverfault.com/questions/691541
复制相似问题