[英]Magento not hitting Varnish cache
我已經在Varnish緩存服務器后面安裝了Nginx的Magento安裝,並且正在使用此擴展程序 。
但是,我從沒有碰到緩存:
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
我知道原因是因為設置了cookie,所以Varnish將請求傳遞給Nginx,但是我找不到原因沒有將其從請求中刪除(這應該根據default.vcl完成, m使用模塊提供的那個)
Magento正在返回響應,指示不應緩存該響應。 因此,清漆不緩存它:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, s-maxage=0
您需要返回公共緩存頭(如果願意,可以使用正的max-age指令)
Cache-Control: public, max-age=600
和/或帶有將來日期的Expires標頭。
另外,如果您使用的是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);
您只需要取消設置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;
}
要么
如果您需要使用擴展名,請遵循此處發布的完整解決方案 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.