Last active
August 10, 2020 08:25
-
-
Save lukecav/bf4d647ab4b8bb309fd8f9f2948ed106 to your computer and use it in GitHub Desktop.
Gzip in Varnish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vcl_recv { | |
# set to Gzip, deflate or remove entirely | |
if (req.http.Accept-Encoding) { | |
if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|mp4|ogg)$") { | |
unset req.http.Accept-Encoding; | |
} elsif (req.http.Accept-Encoding ~ "gzip") { | |
set req.http.Accept-Encoding = "gzip"; | |
} elsif (req.http.Accept-Encoding ~ "deflate") { | |
set req.http.Accept-Encoding = "deflate"; | |
} else { | |
unset req.http.Accept-Encoding; | |
} | |
} | |
sub vcl_backend_response { | |
# Do not Gzip image files in Varnish | |
if (beresp.http.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|mp4|ogg|swf)$") { | |
set beresp.do_gzip = false; | |
} | |
else { | |
set beresp.do_gzip = true; | |
set beresp.http.X-Cache = "ZIP"; | |
} | |
# GZip the cached content if possible | |
if (beresp.http.content-type ~ "text") { | |
set beresp.do_gzip = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.varnish-cache.org/docs/trunk/phk/gzip.html