简体   繁体   English

Magento没有打清漆缓存

[英]Magento not hitting Varnish cache

I have setup a Magento installation with Nginx behind a Varnish cache server and I'm using this extension . 我已经在Varnish缓存服务器后面安装了Nginx的Magento安装,并且正在使用此扩展程序

However, I never get a hit on cache: 但是,我从没有碰到缓存:

HTTP/1.1 200 OK
Server: nginx/1.1.19
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: frontend=8hoas96a6grd1hfb8vqqa5t9a5; expires=Wed, 12-Jun-2013 16:51:51 GMT; path=/; domain=54.232.214.253; H
ttpOnly
Set-Cookie: currency=BRL; expires=Wed, 12-Jun-2013 16:51:51 GMT; path=/; domain=54.232.214.253; httponly
Set-Cookie: PAGECACHE_ENV=xo32rWZFNbsRL%2F05449a0JLaKEguYZObIG0ZFWOVEV3Ajma1%2FUaj%2FA8nPjnTGpBu%2BMw9h72MUATmZTpHe7Ec4A
9pN%2BJcu%2F%2BggyaAX%2FZEZC4%3D; expires=Wed, 12-Jun-2013 16:51:52 GMT; path=/; domain=54.232.214.253; httponly
X-Cache-Debug: 1
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, s-maxage=0
Expires: Mon, 31 Mar 2008 10:00:00 GMT
Pragma: no-cache
X-Purge-URL: /
X-Purge-Host: 54.232.214.253
Date: Wed, 12 Jun 2013 15:51:52 GMT
X-Varnish: 369200976
Age: 0
Via: 1.1 varnish
Connection: keep-alive
X-Cache: MISS
X-Cache-Expires: Mon, 31 Mar 2008 10:00:00 GMT

I understand the reason is because of the cookies being set, so Varnish passes the request on to Nginx, but I can't find the reason it's not removing them from the request (this should be done according to the default.vcl which I'm using the one provided by the module) 我知道原因是因为设置了cookie,所以Varnish将请求传递给Nginx,但是我找不到原因没有将其从请求中删除(这应该根据default.vcl完成, m使用模块提供的那个)

Magento is returning a response indicating it that should not be cached. Magento正在返回响应,指示不应缓存该响应。 So varnish isn't caching it: 因此,清漆不缓存它:

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, s-maxage=0

You need to return public cache headers (with a positive max-age directive if you like) 您需要返回公共缓存头(如果愿意,可以使用正的max-age指令)

Cache-Control: public, max-age=600

and/or an Expires header with a date in the future. 和/或带有将来日期的Expires标头。

Also, the presence of Set-Cookie headers in the response, if you're using the default.vcl, would also result in the item not being cached: 另外,如果您使用的是default.vcl,则响应中存在Set-Cookie标头也将导致不缓存该项目:

# sub vcl_fetch {
#     if (beresp.ttl <= 0s ||
#         beresp.http.Set-Cookie ||  /* Look at this line */
#         beresp.http.Vary == "*") {
#       /*
#        * Mark as "Hit-For-Pass" for the next 2 minutes
#        */
#       set beresp.ttl = 120 s;
#       return (hit_for_pass);

You just have to unset the cookies only and you are done in your .vcl file 您只需要取消设置cookie,就可以在.vcl文件中完成操作了

sub vcl_recv {
    unset req.http.cookie;
}

sub vcl_fetch {
    unset beresp.http.set-cookie;
}

sub vcl_deliver {
 unset resp.http.set-cookie;
}

OR 要么

If you need to use extension then follow complete solution posted here . 如果您需要使用扩展名,请遵循此处发布的完整解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM