Skip to content

Instantly share code, notes, and snippets.

@lukecav

lukecav/default.vcl

Last active Aug 10, 2020
Embed
What would you like to do?
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

This comment has been minimized.

@lukecav

This comment has been minimized.

Copy link
Owner Author

@lukecav lukecav commented Aug 1, 2017

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