From 1f3737b72522f120eceff7613f0390516a5367e3 Mon Sep 17 00:00:00 2001 From: PhoenixPM - BK Date: Wed, 21 Jan 2015 11:50:49 +0100 Subject: [PATCH 1/3] prevent several cache versions for static files because of X-Magento-Vary cookie --- app/code/Magento/PageCache/etc/varnish.vcl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/code/Magento/PageCache/etc/varnish.vcl b/app/code/Magento/PageCache/etc/varnish.vcl index 4b2a337ba321f..7929214655501 100644 --- a/app/code/Magento/PageCache/etc/varnish.vcl +++ b/app/code/Magento/PageCache/etc/varnish.vcl @@ -46,6 +46,18 @@ sub vcl_recv { if (req.request != "GET" && req.request != "HEAD") { return (pass); } + + # normalize url in case of leading HTTP scheme and domain + set req.url = regsub(req.url, "^http[s]?://[^/]+", ""); + + # collect all cookies + std.collect(req.http.Cookie); + + # static files are always cacheable. remove SSL flag and cookie + if (req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$") { + unset req.http.Https; + unset req.http.Cookie; + } set req.grace = 1m; From 28daee5fea15a57378d068f5d4f6ee9d2b3adcaa Mon Sep 17 00:00:00 2001 From: PhoenixPM - BK Date: Wed, 21 Jan 2015 14:58:34 +0100 Subject: [PATCH 2/3] fixed static file path to pub for magento2 --- app/code/Magento/PageCache/etc/varnish.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/PageCache/etc/varnish.vcl b/app/code/Magento/PageCache/etc/varnish.vcl index 7929214655501..7de5e31ae846f 100644 --- a/app/code/Magento/PageCache/etc/varnish.vcl +++ b/app/code/Magento/PageCache/etc/varnish.vcl @@ -54,7 +54,7 @@ sub vcl_recv { std.collect(req.http.Cookie); # static files are always cacheable. remove SSL flag and cookie - if (req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$") { + if (req.url ~ "^/pub/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$") { unset req.http.Https; unset req.http.Cookie; } From dcb3c67fdeca0007d913c558bcbc6bf19e942281 Mon Sep 17 00:00:00 2001 From: PhoenixPM - BK Date: Wed, 21 Jan 2015 17:30:08 +0100 Subject: [PATCH 3/3] made /pub/ optional for static content --- app/code/Magento/PageCache/etc/varnish.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/PageCache/etc/varnish.vcl b/app/code/Magento/PageCache/etc/varnish.vcl index 7de5e31ae846f..2b90ee0e3ef14 100644 --- a/app/code/Magento/PageCache/etc/varnish.vcl +++ b/app/code/Magento/PageCache/etc/varnish.vcl @@ -54,7 +54,7 @@ sub vcl_recv { std.collect(req.http.Cookie); # static files are always cacheable. remove SSL flag and cookie - if (req.url ~ "^/pub/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$") { + if (req.url ~ "^/(pub/)?(media|static)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico|woff|svg)$") { unset req.http.Https; unset req.http.Cookie; }