1
1
vcl 4 .0 ;
2
-
2
+
3
3
import std;
4
4
# The minimal Varnish version is 4.0
5
-
5
+
6
6
backend default {
7
7
.host = " /* {{ host }} */" ;
8
8
.port = " /* {{ port }} */" ;
@@ -23,7 +23,7 @@ sub vcl_recv {
23
23
ban (" obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern );
24
24
return (synth (200, "Purged"));
25
25
}
26
-
26
+
27
27
if (req.method != " GET" &&
28
28
req.method != " HEAD" &&
29
29
req.method != " PUT" &&
@@ -34,7 +34,7 @@ sub vcl_recv {
34
34
/* Non-RFC2616 or CONNECT which is weird. */
35
35
return (pipe );
36
36
}
37
-
37
+
38
38
# We only deal with GET and HEAD by default
39
39
if (req.method != " GET" && req.method != " HEAD" ) {
40
40
return (pass );
@@ -51,6 +51,26 @@ sub vcl_recv {
51
51
# collect all cookies
52
52
std.collect (req.http.Cookie );
53
53
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
+
54
74
# static files are always cacheable. remove SSL flag and cookie
55
75
if (req.url ~ " ^/(pub/)?(media|static)/.*\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$" ) {
56
76
unset req.http.Https ;
@@ -64,6 +84,18 @@ sub vcl_hash {
64
84
if (req.http.cookie ~ " X-Magento-Vary=" ) {
65
85
hash_data (regsub (req.http.cookie , " ^.*?X-Magento-Vary=([^;]+);*.*$" , " \1" ));
66
86
}
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
+ }
67
99
/* {{ design_exceptions_code }} */
68
100
}
69
101
@@ -75,7 +107,7 @@ sub vcl_backend_response {
75
107
if (bereq.url ~ " \.js$" || beresp.http.content-type ~ " text" ) {
76
108
set beresp.do_gzip = true ;
77
109
}
78
-
110
+
79
111
# cache only successfully responses and 404s
80
112
if (beresp.status != 200 && beresp.status != 404 ) {
81
113
set beresp.ttl = 0s ;
0 commit comments