与Magento 1.8.1 Varnish社区编辑没有获得缓存结果

时间:2014-08-01 14:59:17

标签: caching varnish magento-1.8 varnish-vcl

我是Varnish Cache的新手。我已成功在Cent OS服务器上安装了Varnish 4(最新版本)并完美配置。我还在Response头中获得了X-Varnish,Via 1.1 varnish - v4。我发现一切都很完美。如果我停止清漆,网站就会停止,这似乎是正确的。

我的问题是,尽管清漆配置正确但我没有足够的速度。我想,我没有得到清漆缓存结果,它看起来服务器总是被称为后端服务器以获得结果。通常,没有清漆需要3-4秒才能获得结果。安装清漆后,需要相同的时间。

Resonse标题

  

Accept-Ranges字节年龄0 Cache-Controlno-store,no-cache,   must-revalidate,post-check = 0,pre-check = 0 Connectionkeep-alive   内容EncodinggzipContent-的TypeText / HTML; charset = UTF-8DateFri,01   2014年8月14:08:51 GMTExpiresThu,1981年11月19日08:52:00   GMTPragmano-cacheServerApache / 2.2.15   (CentOS的)设置-Cookiefrontend = rfdi8hd6kq136puafk93lm0ra7;期满=星期五,   01-Aug-2014 15:08:51 GMT;路径= /;域= www.usapooldirect.com;   httponlyTransfer-EncodingchunkedVaryAccept-Encoding,用户代理通过   1.1 varnish-v4 X-Powered-By PHP / 5.3.3X-Varnish

请求标题

  

Accepttext / html,application / xhtml + xml,application / xml; q = 0.9   , / 的; Q = 0.8Accept-Encodinggzip,   deflateAccept-Languageen美,恩; Q = 0.5Connectionkeep-aliveCookiefrontend = rfdi8hd6kq136puafk93lm0ra7;   external_no_cache = 1;   adminhtml = pt3bt6t30m4vtqdsm1ldv716v7Hostwww.usapooldirect.com   参考资料://www.usapooldirect.com/User-Agent Mozilla / 5.0(X11;   Ubuntu的; Linux x86_64; rv:31.0)Gecko / 20100101 Firefox / 31.0

谢谢,

ANKIT

3 个答案:

答案 0 :(得分:2)

你应该在Varnishstat的帮助下检查清漆。

如果代码是从Varnish缓存或后端提供的,您还可以在代码中添加以下代码。

sub vcl_deliver {
if (obj.hits > 0) {
    set resp.http.X-Cache = "HIT ("+obj.hits+")";
} else {
    set resp.http.X-Cache = "MISS";
    #    set resp.http.X-Cache-Hash = obj.http.hash;
}
return (deliver);
}

答案 1 :(得分:2)

无论您使用什么模块来改进缓存,只要涉及Magento - 即使它只是用于确定从其缓存加载哪些数据 - 它也会很慢。 Varnish一直是加速Magento的解决方案。

但是在Magento 1.8.1之后,Varnish缓存实际上变得毫无用处。你可以在这里看到how you can configure Varnish Cache with Magento 1.8.1!以及。

答案 2 :(得分:1)

您可以使用以下示例清漆文件。

backend default {
.host = "localhost";
.port = "80";
}

sub vcl_recv {
if (req.http.x-forwarded-for) {
remove req.http.X-Forwarded-For;
set req.http.x-forwarded-for = req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}

if (!req.backend.healthy) {
unset req.http.Cookie;
}

if (req.backend.healthy) {
set req.grace = 60s;
} else {
set req.grace = 24h;
}

if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
return (pipe);
}
if (req.request == "POST") {
return(pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}

if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
remove req.http.Accept-Encoding;
}
elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
}
elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
set req.http.Accept-Encoding = "deflate";
}
}       else {
remove req.http.Accept-Encoding;
}

if (!req.backend.healthy) {
unset req.http.Cookie;
}
if (req.http.Cookie) {
return (pass);
}
return (lookup);
}

sub vcl_pipe {
return (pipe);
}

sub vcl_pass {
return (pass);
}

sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (hash);
}

sub vcl_hit {
return (deliver);
}

sub vcl_miss {
return (fetch);
}

sub vcl_fetch {
if (beresp.status == 404 || beresp.status == 503) {
set beresp.ttl = 0s;
return (hit_for_pass);
}
if (!req.backend.healthy) {
set beresp.ttl = 1h;
unset beresp.http.set-Cookie;
}
if (beresp.http.Set-Cookie) {
return (hit_for_pass);
}
set beresp.grace = 24h;
return (deliver);
}

sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT";
}
else {
set resp.http.X-Varnish-Cache = "MISS";
}
}

sub vcl_init {
return (ok);
}

sub vcl_fini {
return (ok);
}

sub vcl_error {
return(deliver);
}