Skip to content

Commit 95d9758

Browse files
author
Hayder Sharhan
committed
Merge remote-tracking branch 'remotes/api/MAGETWO-49876' into ext-public-pull-requests
2 parents 1420b60 + 48ca7e3 commit 95d9758

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
vcl 4.0;
2-
2+
33
import std;
44
# The minimal Varnish version is 4.0
5-
5+
66
backend default {
77
.host = "/* {{ host }} */";
88
.port = "/* {{ port }} */";
@@ -23,7 +23,7 @@ sub vcl_recv {
2323
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
2424
return (synth(200, "Purged"));
2525
}
26-
26+
2727
if (req.method != "GET" &&
2828
req.method != "HEAD" &&
2929
req.method != "PUT" &&
@@ -34,7 +34,7 @@ sub vcl_recv {
3434
/* Non-RFC2616 or CONNECT which is weird. */
3535
return (pipe);
3636
}
37-
37+
3838
# We only deal with GET and HEAD by default
3939
if (req.method != "GET" && req.method != "HEAD") {
4040
return (pass);
@@ -51,6 +51,26 @@ sub vcl_recv {
5151
# collect all cookies
5252
std.collect(req.http.Cookie);
5353

54+
# Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
55+
if (req.http.Accept-Encoding) {
56+
if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
57+
# No point in compressing these
58+
unset req.http.Accept-Encoding;
59+
} elsif (req.http.Accept-Encoding ~ "gzip") {
60+
set req.http.Accept-Encoding = "gzip";
61+
} elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
62+
set req.http.Accept-Encoding = "deflate";
63+
} else {
64+
# unkown algorithm
65+
unset req.http.Accept-Encoding;
66+
}
67+
}
68+
69+
# Remove Google gclid parameters to minimize the cache objects
70+
set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA"
71+
set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
72+
set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
73+
5474
# static files are always cacheable. remove SSL flag and cookie
5575
if (req.url ~ "^/(pub/)?(media|static)/.*\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$") {
5676
unset req.http.Https;
@@ -64,6 +84,18 @@ sub vcl_hash {
6484
if (req.http.cookie ~ "X-Magento-Vary=") {
6585
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
6686
}
87+
88+
# For multi site configurations to not cache each other's content
89+
if (req.http.host) {
90+
hash_data(req.http.host);
91+
} else {
92+
hash_data(server.ip);
93+
}
94+
95+
# To make sure http users don't see ssl warning
96+
if (req.http.X-Forwarded-Proto) {
97+
hash_data(req.http.X-Forwarded-Proto);
98+
}
6799
/* {{ design_exceptions_code }} */
68100
}
69101

@@ -75,7 +107,7 @@ sub vcl_backend_response {
75107
if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") {
76108
set beresp.do_gzip = true;
77109
}
78-
110+
79111
# cache only successfully responses and 404s
80112
if (beresp.status != 200 && beresp.status != 404) {
81113
set beresp.ttl = 0s;

0 commit comments

Comments
 (0)