Skip to content

Instantly share code, notes, and snippets.

@lukecav
Last active August 10, 2020 08:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukecav/bf4d647ab4b8bb309fd8f9f2948ed106 to your computer and use it in GitHub Desktop.
Save lukecav/bf4d647ab4b8bb309fd8f9f2948ed106 to your computer and use it in GitHub Desktop.
Gzip in Varnish
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;
}
}
@lukecav
Copy link
Author

lukecav commented Aug 1, 2017

@lukecav
Copy link
Author

lukecav commented Aug 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment