├── screenshots ├── magento-222-admin-01.png ├── magento-222-admin-02.png ├── magento-222-admin-03.png ├── magento-222-admin-04.png ├── magento-222-admin-05.png ├── magento-222-admin-06.png ├── magento-222-admin-07.png ├── magento-222-admin-08.png ├── magento-222-admin-01a.png ├── magento-222-admin-01b.png ├── magento-222-admin-04b.png ├── magento-222-admin-05a.png ├── magento-222-admin-06b.png ├── nginx-amplify-nginx-160318-01.png ├── nginx-amplify-nginx-160318-02.png ├── nginx-amplify-nginx-160318-03.png ├── wpt-lighthouse-redis-cache-01.png ├── wpt-lighthouse-varnish-cache-01.png ├── magento-222-admin-varnish-cache-01.png ├── wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-01.png ├── wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-02.png ├── wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-03.png ├── wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-04.png ├── wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-01.png ├── wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-02.png ├── wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-03.png ├── wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-04.png └── wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-05.png └── vcl ├── varnish4 └── varnish.vcl └── varnish5 ├── varnish.vcl └── varnish-custom.vcl /screenshots/magento-222-admin-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-01.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-02.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-03.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-04.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-05.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-06.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-07.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-08.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-01a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-01a.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-01b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-01b.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-04b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-04b.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-05a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-05a.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-06b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-06b.png -------------------------------------------------------------------------------- /screenshots/nginx-amplify-nginx-160318-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/nginx-amplify-nginx-160318-01.png -------------------------------------------------------------------------------- /screenshots/nginx-amplify-nginx-160318-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/nginx-amplify-nginx-160318-02.png -------------------------------------------------------------------------------- /screenshots/nginx-amplify-nginx-160318-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/nginx-amplify-nginx-160318-03.png -------------------------------------------------------------------------------- /screenshots/wpt-lighthouse-redis-cache-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-lighthouse-redis-cache-01.png -------------------------------------------------------------------------------- /screenshots/wpt-lighthouse-varnish-cache-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-lighthouse-varnish-cache-01.png -------------------------------------------------------------------------------- /screenshots/magento-222-admin-varnish-cache-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/magento-222-admin-varnish-cache-01.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-01.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-02.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-03.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-222-centminmod-nginx-default-theme-cable-dulles-04.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-01.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-02.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-03.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-04.png -------------------------------------------------------------------------------- /screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/centminmod/centminmod-magento2/HEAD/screenshots/wpt-magento-223-centminmod-nginx-default-theme-cable-dulles-varnishcache-05.png -------------------------------------------------------------------------------- /vcl/varnish4/varnish.vcl: -------------------------------------------------------------------------------- 1 | vcl 4.0; 2 | 3 | import std; 4 | # The minimal Varnish version is 4.0 5 | # For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https' 6 | 7 | backend default { 8 | .host = "localhost"; 9 | .port = "8080"; 10 | .first_byte_timeout = 600s; 11 | .probe = { 12 | .url = "/health_check.php"; 13 | .timeout = 2s; 14 | .interval = 5s; 15 | .window = 10; 16 | .threshold = 5; 17 | } 18 | } 19 | 20 | acl purge { 21 | "localhost"; 22 | } 23 | 24 | sub vcl_recv { 25 | if (req.method == "PURGE") { 26 | if (client.ip !~ purge) { 27 | return (synth(405, "Method not allowed")); 28 | } 29 | # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header 30 | # has been added to the response in your backend server config. This is used, for example, by the 31 | # capistrano-magento2 gem for purging old content from varnish during it's deploy routine. 32 | if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) { 33 | return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required")); 34 | } 35 | if (req.http.X-Magento-Tags-Pattern) { 36 | ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern); 37 | } 38 | if (req.http.X-Pool) { 39 | ban("obj.http.X-Pool ~ " + req.http.X-Pool); 40 | } 41 | return (synth(200, "Purged")); 42 | } 43 | 44 | if (req.method != "GET" && 45 | req.method != "HEAD" && 46 | req.method != "PUT" && 47 | req.method != "POST" && 48 | req.method != "TRACE" && 49 | req.method != "OPTIONS" && 50 | req.method != "DELETE") { 51 | /* Non-RFC2616 or CONNECT which is weird. */ 52 | return (pipe); 53 | } 54 | 55 | # We only deal with GET and HEAD by default 56 | if (req.method != "GET" && req.method != "HEAD") { 57 | return (pass); 58 | } 59 | 60 | # Bypass shopping cart, checkout and search requests 61 | if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") { 62 | return (pass); 63 | } 64 | 65 | # Bypass health check requests 66 | if (req.url ~ "/pub/health_check.php") { 67 | return (pass); 68 | } 69 | 70 | # Set initial grace period usage status 71 | set req.http.grace = "none"; 72 | 73 | # normalize url in case of leading HTTP scheme and domain 74 | set req.url = regsub(req.url, "^http[s]?://", ""); 75 | 76 | # collect all cookies 77 | std.collect(req.http.Cookie); 78 | 79 | # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression 80 | if (req.http.Accept-Encoding) { 81 | if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") { 82 | # No point in compressing these 83 | unset req.http.Accept-Encoding; 84 | } elsif (req.http.Accept-Encoding ~ "gzip") { 85 | set req.http.Accept-Encoding = "gzip"; 86 | } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") { 87 | set req.http.Accept-Encoding = "deflate"; 88 | } else { 89 | # unkown algorithm 90 | unset req.http.Accept-Encoding; 91 | } 92 | } 93 | 94 | # Remove Google gclid parameters to minimize the cache objects 95 | set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA" 96 | set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar" 97 | set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz" 98 | 99 | # Static files caching 100 | if (req.url ~ "^/(pub/)?(media|static)/") { 101 | # Static files should not be cached by default 102 | return (pass); 103 | 104 | # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines 105 | #unset req.http.Https; 106 | #unset req.http.X-Forwarded-Proto; 107 | #unset req.http.Cookie; 108 | } 109 | 110 | return (hash); 111 | } 112 | 113 | sub vcl_hash { 114 | if (req.http.cookie ~ "X-Magento-Vary=") { 115 | hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1")); 116 | } 117 | 118 | # For multi site configurations to not cache each other's content 119 | if (req.http.host) { 120 | hash_data(req.http.host); 121 | } else { 122 | hash_data(server.ip); 123 | } 124 | 125 | # To make sure http users don't see ssl warning 126 | if (req.http.X-Forwarded-Proto) { 127 | hash_data(req.http.X-Forwarded-Proto); 128 | } 129 | 130 | } 131 | 132 | sub vcl_backend_response { 133 | 134 | set beresp.grace = 3d; 135 | 136 | if (beresp.http.content-type ~ "text") { 137 | set beresp.do_esi = true; 138 | } 139 | 140 | if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") { 141 | set beresp.do_gzip = true; 142 | } 143 | 144 | if (beresp.http.X-Magento-Debug) { 145 | set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; 146 | } 147 | 148 | # cache only successfully responses and 404s 149 | if (beresp.status != 200 && beresp.status != 404) { 150 | set beresp.ttl = 0s; 151 | set beresp.uncacheable = true; 152 | return (deliver); 153 | } elsif (beresp.http.Cache-Control ~ "private") { 154 | set beresp.uncacheable = true; 155 | set beresp.ttl = 86400s; 156 | return (deliver); 157 | } 158 | 159 | # validate if we need to cache it and prevent from setting cookie 160 | # images, css and js are cacheable by default so we have to remove cookie also 161 | if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { 162 | unset beresp.http.set-cookie; 163 | } 164 | 165 | # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass 166 | if (beresp.ttl <= 0s || 167 | beresp.http.Surrogate-control ~ "no-store" || 168 | (!beresp.http.Surrogate-Control && 169 | beresp.http.Cache-Control ~ "no-cache|no-store") || 170 | beresp.http.Vary == "*") { 171 | # Mark as Hit-For-Pass for the next 2 minutes 172 | set beresp.ttl = 120s; 173 | set beresp.uncacheable = true; 174 | } 175 | 176 | return (deliver); 177 | } 178 | 179 | sub vcl_deliver { 180 | if (resp.http.X-Magento-Debug) { 181 | if (resp.http.x-varnish ~ " ") { 182 | set resp.http.X-Magento-Cache-Debug = "HIT"; 183 | set resp.http.Grace = req.http.grace; 184 | } else { 185 | set resp.http.X-Magento-Cache-Debug = "MISS"; 186 | } 187 | } else { 188 | unset resp.http.Age; 189 | } 190 | 191 | # Not letting browser to cache non-static files. 192 | if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") { 193 | set resp.http.Pragma = "no-cache"; 194 | set resp.http.Expires = "-1"; 195 | set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; 196 | } 197 | 198 | unset resp.http.X-Magento-Debug; 199 | unset resp.http.X-Magento-Tags; 200 | unset resp.http.X-Powered-By; 201 | unset resp.http.Server; 202 | unset resp.http.X-Varnish; 203 | unset resp.http.Via; 204 | unset resp.http.Link; 205 | } 206 | 207 | sub vcl_hit { 208 | if (obj.ttl >= 0s) { 209 | # Hit within TTL period 210 | return (deliver); 211 | } 212 | if (std.healthy(req.backend_hint)) { 213 | if (obj.ttl + 300s > 0s) { 214 | # Hit after TTL expiration, but within grace period 215 | set req.http.grace = "normal (healthy server)"; 216 | return (deliver); 217 | } else { 218 | # Hit after TTL and grace expiration 219 | return (fetch); 220 | } 221 | } else { 222 | # server is not healthy, retrieve from cache 223 | set req.http.grace = "unlimited (unhealthy server)"; 224 | return (deliver); 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /vcl/varnish5/varnish.vcl: -------------------------------------------------------------------------------- 1 | # VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 5 2 | vcl 4.0; 3 | 4 | import std; 5 | # The minimal Varnish version is 5.0 6 | # For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https' 7 | 8 | backend default { 9 | .host = "localhost"; 10 | .port = "8080"; 11 | .first_byte_timeout = 600s; 12 | .probe = { 13 | .url = "/health_check.php"; 14 | .timeout = 2s; 15 | .interval = 5s; 16 | .window = 10; 17 | .threshold = 5; 18 | } 19 | } 20 | 21 | acl purge { 22 | "localhost"; 23 | } 24 | 25 | sub vcl_recv { 26 | if (req.method == "PURGE") { 27 | if (client.ip !~ purge) { 28 | return (synth(405, "Method not allowed")); 29 | } 30 | # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header 31 | # has been added to the response in your backend server config. This is used, for example, by the 32 | # capistrano-magento2 gem for purging old content from varnish during it's deploy routine. 33 | if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) { 34 | return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required")); 35 | } 36 | if (req.http.X-Magento-Tags-Pattern) { 37 | ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern); 38 | } 39 | if (req.http.X-Pool) { 40 | ban("obj.http.X-Pool ~ " + req.http.X-Pool); 41 | } 42 | return (synth(200, "Purged")); 43 | } 44 | 45 | if (req.method != "GET" && 46 | req.method != "HEAD" && 47 | req.method != "PUT" && 48 | req.method != "POST" && 49 | req.method != "TRACE" && 50 | req.method != "OPTIONS" && 51 | req.method != "DELETE") { 52 | /* Non-RFC2616 or CONNECT which is weird. */ 53 | return (pipe); 54 | } 55 | 56 | # We only deal with GET and HEAD by default 57 | if (req.method != "GET" && req.method != "HEAD") { 58 | return (pass); 59 | } 60 | 61 | # Bypass shopping cart, checkout and search requests 62 | if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") { 63 | return (pass); 64 | } 65 | 66 | # Bypass health check requests 67 | if (req.url ~ "/pub/health_check.php") { 68 | return (pass); 69 | } 70 | 71 | # Set initial grace period usage status 72 | set req.http.grace = "none"; 73 | 74 | # normalize url in case of leading HTTP scheme and domain 75 | set req.url = regsub(req.url, "^http[s]?://", ""); 76 | 77 | # collect all cookies 78 | std.collect(req.http.Cookie); 79 | 80 | # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression 81 | if (req.http.Accept-Encoding) { 82 | if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") { 83 | # No point in compressing these 84 | unset req.http.Accept-Encoding; 85 | } elsif (req.http.Accept-Encoding ~ "gzip") { 86 | set req.http.Accept-Encoding = "gzip"; 87 | } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") { 88 | set req.http.Accept-Encoding = "deflate"; 89 | } else { 90 | # unkown algorithm 91 | unset req.http.Accept-Encoding; 92 | } 93 | } 94 | 95 | # Remove Google gclid parameters to minimize the cache objects 96 | set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA" 97 | set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar" 98 | set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz" 99 | 100 | # Static files caching 101 | if (req.url ~ "^/(pub/)?(media|static)/") { 102 | # Static files should not be cached by default 103 | return (pass); 104 | 105 | # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines 106 | #unset req.http.Https; 107 | #unset req.http.X-Forwarded-Proto; 108 | #unset req.http.Cookie; 109 | } 110 | 111 | return (hash); 112 | } 113 | 114 | sub vcl_hash { 115 | if (req.http.cookie ~ "X-Magento-Vary=") { 116 | hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1")); 117 | } 118 | 119 | # For multi site configurations to not cache each other's content 120 | if (req.http.host) { 121 | hash_data(req.http.host); 122 | } else { 123 | hash_data(server.ip); 124 | } 125 | 126 | # To make sure http users don't see ssl warning 127 | if (req.http.X-Forwarded-Proto) { 128 | hash_data(req.http.X-Forwarded-Proto); 129 | } 130 | 131 | } 132 | 133 | sub vcl_backend_response { 134 | 135 | set beresp.grace = 3d; 136 | 137 | if (beresp.http.content-type ~ "text") { 138 | set beresp.do_esi = true; 139 | } 140 | 141 | if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") { 142 | set beresp.do_gzip = true; 143 | } 144 | 145 | if (beresp.http.X-Magento-Debug) { 146 | set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; 147 | } 148 | 149 | # cache only successfully responses and 404s 150 | if (beresp.status != 200 && beresp.status != 404) { 151 | set beresp.ttl = 0s; 152 | set beresp.uncacheable = true; 153 | return (deliver); 154 | } elsif (beresp.http.Cache-Control ~ "private") { 155 | set beresp.uncacheable = true; 156 | set beresp.ttl = 86400s; 157 | return (deliver); 158 | } 159 | 160 | # validate if we need to cache it and prevent from setting cookie 161 | # images, css and js are cacheable by default so we have to remove cookie also 162 | if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { 163 | unset beresp.http.set-cookie; 164 | } 165 | 166 | # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass 167 | if (beresp.ttl <= 0s || 168 | beresp.http.Surrogate-control ~ "no-store" || 169 | (!beresp.http.Surrogate-Control && 170 | beresp.http.Cache-Control ~ "no-cache|no-store") || 171 | beresp.http.Vary == "*") { 172 | # Mark as Hit-For-Pass for the next 2 minutes 173 | set beresp.ttl = 120s; 174 | set beresp.uncacheable = true; 175 | } 176 | 177 | return (deliver); 178 | } 179 | 180 | sub vcl_deliver { 181 | if (resp.http.X-Magento-Debug) { 182 | if (resp.http.x-varnish ~ " ") { 183 | set resp.http.X-Magento-Cache-Debug = "HIT"; 184 | set resp.http.Grace = req.http.grace; 185 | } else { 186 | set resp.http.X-Magento-Cache-Debug = "MISS"; 187 | } 188 | } else { 189 | unset resp.http.Age; 190 | } 191 | 192 | # Not letting browser to cache non-static files. 193 | if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") { 194 | set resp.http.Pragma = "no-cache"; 195 | set resp.http.Expires = "-1"; 196 | set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; 197 | } 198 | 199 | unset resp.http.X-Magento-Debug; 200 | unset resp.http.X-Magento-Tags; 201 | unset resp.http.X-Powered-By; 202 | unset resp.http.Server; 203 | unset resp.http.X-Varnish; 204 | unset resp.http.Via; 205 | unset resp.http.Link; 206 | } 207 | 208 | sub vcl_hit { 209 | if (obj.ttl >= 0s) { 210 | # Hit within TTL period 211 | return (deliver); 212 | } 213 | if (std.healthy(req.backend_hint)) { 214 | if (obj.ttl + 300s > 0s) { 215 | # Hit after TTL expiration, but within grace period 216 | set req.http.grace = "normal (healthy server)"; 217 | return (deliver); 218 | } else { 219 | # Hit after TTL and grace expiration 220 | return (miss); 221 | } 222 | } else { 223 | # server is not healthy, retrieve from cache 224 | set req.http.grace = "unlimited (unhealthy server)"; 225 | return (deliver); 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /vcl/varnish5/varnish-custom.vcl: -------------------------------------------------------------------------------- 1 | # VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 5 2 | vcl 4.0; 3 | 4 | import std; 5 | # The minimal Varnish version is 5.0 6 | # For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https' 7 | 8 | backend default { 9 | .host = "localhost"; 10 | .port = "8080"; 11 | .first_byte_timeout = 600s; 12 | .connect_timeout = 5s; 13 | .between_bytes_timeout = 3s; 14 | .probe = { 15 | .url = "/pub/health_check.php"; 16 | .timeout = 3s; 17 | .interval = 5s; 18 | .window = 10; 19 | .threshold = 5; 20 | } 21 | } 22 | 23 | acl purge { 24 | "localhost"; 25 | } 26 | 27 | sub vcl_recv { 28 | if (req.method == "PURGE") { 29 | if (client.ip !~ purge) { 30 | return (synth(405, "Method not allowed")); 31 | } 32 | # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header 33 | # has been added to the response in your backend server config. This is used, for example, by the 34 | # capistrano-magento2 gem for purging old content from varnish during it's deploy routine. 35 | if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) { 36 | return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required")); 37 | } 38 | if (req.http.X-Magento-Tags-Pattern) { 39 | ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern); 40 | } 41 | if (req.http.X-Pool) { 42 | ban("obj.http.X-Pool ~ " + req.http.X-Pool); 43 | } 44 | return (synth(200, "Purged")); 45 | } 46 | 47 | if (req.method != "GET" && 48 | req.method != "HEAD" && 49 | req.method != "PUT" && 50 | req.method != "POST" && 51 | req.method != "TRACE" && 52 | req.method != "OPTIONS" && 53 | req.method != "DELETE") { 54 | /* Non-RFC2616 or CONNECT which is weird. */ 55 | return (pipe); 56 | } 57 | 58 | if (req.url ~ "/?nocache=1") { 59 | return (pass); 60 | } 61 | 62 | # We only deal with GET and HEAD by default 63 | if (req.method != "GET" && req.method != "HEAD") { 64 | return (pass); 65 | } 66 | 67 | # Bypass shopping cart, checkout and search requests 68 | if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") { 69 | return (pass); 70 | } 71 | 72 | # Bypass health check requests 73 | if (req.url ~ "/pub/health_check.php") { 74 | return (pass); 75 | } 76 | 77 | # Set initial grace period usage status 78 | set req.http.grace = "none"; 79 | 80 | # normalize url in case of leading HTTP scheme and domain 81 | set req.url = regsub(req.url, "^http[s]?://", ""); 82 | 83 | # collect all cookies 84 | std.collect(req.http.Cookie); 85 | 86 | # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression 87 | if (req.http.Accept-Encoding) { 88 | if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") { 89 | # No point in compressing these 90 | unset req.http.Accept-Encoding; 91 | } elsif (req.http.Accept-Encoding ~ "gzip") { 92 | set req.http.Accept-Encoding = "gzip"; 93 | } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") { 94 | set req.http.Accept-Encoding = "deflate"; 95 | } else { 96 | # unkown algorithm 97 | unset req.http.Accept-Encoding; 98 | } 99 | } 100 | 101 | # brotli 102 | if(req.http.Accept-Encoding ~ "br" && req.url !~ "\.(jpg|png|gif|gz|mp3|mov|avi|mpg|mp4|swf|wmf)$") { 103 | set req.http.X-brotli = "true"; 104 | } 105 | 106 | # Remove Google gclid parameters to minimize the cache objects 107 | set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA" 108 | set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar" 109 | set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz" 110 | 111 | # Remove DoubleClick offensive cookies 112 | set req.http.Cookie = regsuball(req.http.Cookie, "__gads=[^;]+(; )?", ""); 113 | # Remove the AddThis cookies 114 | set req.http.Cookie = regsuball(req.http.Cookie, "__atuv.=[^;]+(; )?", ""); 115 | 116 | # Large static files are delivered directly to the end-user without 117 | # waiting for Varnish to fully read the file first. 118 | # Varnish 4 fully supports Streaming, so set do_stream in vcl_backend_response() 119 | # https://www.varnish-software.com/wiki/content/tutorials/varnish/sample_vclTemplate.html#turn-on-varnish-support-for-streaming 120 | if (req.url ~ "^[^?]*\.(7z|avi|bz2|flac|flv|gz|mka|mkv|mov|mp3|mp4|mpeg|mpg|ogg|ogm|opus|rar|tar|tgz|tbz|txz|wav|webm|xz|zip)(\?.*)?$") { 121 | unset req.http.Cookie; 122 | return (hash); 123 | } 124 | 125 | # Static files caching 126 | if (req.url ~ "^/(pub/)?(media|static)/") { 127 | # Static files should not be cached by default 128 | return (pass); 129 | 130 | # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines 131 | #unset req.http.Https; 132 | #unset req.http.X-Forwarded-Proto; 133 | #unset req.http.Cookie; 134 | } 135 | 136 | return (hash); 137 | } 138 | 139 | sub vcl_backend_fetch 140 | { 141 | if(bereq.http.X-brotli == "true") { 142 | set bereq.http.Accept-Encoding = "br"; 143 | unset bereq.http.X-brotli; 144 | } 145 | } 146 | 147 | sub vcl_hash { 148 | if (req.http.cookie ~ "X-Magento-Vary=") { 149 | hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1")); 150 | } 151 | 152 | # brotli 153 | if(req.http.X-brotli == "true") { 154 | hash_data("brotli"); 155 | } 156 | 157 | # For multi site configurations to not cache each other's content 158 | if (req.http.host) { 159 | hash_data(req.http.host); 160 | } else { 161 | hash_data(server.ip); 162 | } 163 | 164 | # To make sure http users don't see ssl warning 165 | if (req.http.X-Forwarded-Proto) { 166 | hash_data(req.http.X-Forwarded-Proto); 167 | } 168 | 169 | } 170 | 171 | sub vcl_backend_response { 172 | 173 | set beresp.grace = 3d; 174 | 175 | if (beresp.http.content-type ~ "text") { 176 | set beresp.do_esi = true; 177 | } 178 | 179 | if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") { 180 | set beresp.do_gzip = true; 181 | } 182 | 183 | if (bereq.url ~ "^[^?]*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)(\?.*)?$") { 184 | unset beresp.http.set-cookie; 185 | } 186 | 187 | if (beresp.http.X-Magento-Debug) { 188 | set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; 189 | } 190 | 191 | # cache only successfully responses and 404s 192 | if (beresp.status != 200 && beresp.status != 404) { 193 | set beresp.ttl = 0s; 194 | set beresp.uncacheable = true; 195 | return (deliver); 196 | } elsif (beresp.http.Cache-Control ~ "private") { 197 | set beresp.uncacheable = true; 198 | set beresp.ttl = 86400s; 199 | return (deliver); 200 | } 201 | 202 | # validate if we need to cache it and prevent from setting cookie 203 | # images, css and js are cacheable by default so we have to remove cookie also 204 | if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { 205 | unset beresp.http.set-cookie; 206 | } 207 | 208 | # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass 209 | if (beresp.ttl <= 0s || 210 | beresp.http.Surrogate-control ~ "no-store" || 211 | (!beresp.http.Surrogate-Control && 212 | beresp.http.Cache-Control ~ "no-cache|no-store") || 213 | beresp.http.Vary == "*") { 214 | # Mark as Hit-For-Pass for the next 2 minutes 215 | set beresp.ttl = 120s; 216 | set beresp.uncacheable = true; 217 | } 218 | 219 | return (deliver); 220 | } 221 | 222 | sub vcl_deliver { 223 | if (resp.http.X-Magento-Debug) { 224 | if (resp.http.x-varnish ~ " ") { 225 | set resp.http.X-Magento-Cache-Debug = "HIT"; 226 | set resp.http.Grace = req.http.grace; 227 | } else { 228 | set resp.http.X-Magento-Cache-Debug = "MISS"; 229 | } 230 | } else { 231 | unset resp.http.Age; 232 | } 233 | 234 | # Not letting browser to cache non-static files. 235 | if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") { 236 | set resp.http.Pragma = "no-cache"; 237 | set resp.http.Expires = "-1"; 238 | set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; 239 | } 240 | 241 | unset resp.http.X-Magento-Debug; 242 | unset resp.http.X-Magento-Tags; 243 | unset resp.http.X-Powered-By; 244 | unset resp.http.Server; 245 | unset resp.http.X-Varnish; 246 | unset resp.http.Via; 247 | # https://github.com/magento/magento2/issues/8126 248 | #unset resp.http.Link; 249 | } 250 | 251 | sub vcl_hit { 252 | if (obj.ttl >= 0s) { 253 | # Hit within TTL period 254 | return (deliver); 255 | } 256 | if (std.healthy(req.backend_hint)) { 257 | if (obj.ttl + 300s > 0s) { 258 | # Hit after TTL expiration, but within grace period 259 | set req.http.grace = "normal (healthy server)"; 260 | return (deliver); 261 | } else { 262 | # Hit after TTL and grace expiration 263 | return (miss); 264 | } 265 | } else { 266 | # server is not healthy, retrieve from cache 267 | set req.http.grace = "unlimited (unhealthy server)"; 268 | return (deliver); 269 | } 270 | } 271 | --------------------------------------------------------------------------------