Skip to content

Instantly share code, notes, and snippets.

@wpsmithtwc
Forked from TomCan/varnish.vcl
Created March 28, 2017 11:54
Show Gist options
  • Save wpsmithtwc/bde757afb72b3a2abd6d0f7f8249bbbe to your computer and use it in GitHub Desktop.
Save wpsmithtwc/bde757afb72b3a2abd6d0f7f8249bbbe to your computer and use it in GitHub Desktop.
Enable gzip compression in Varnish
sub vcl_recv {
...
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpeg|jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
unset req.http.Accept-Encoding;
} elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate" &&
req.http.user-agent !~ "MSIE") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
...
}
sub vcl_backend_response {
...
if (beresp.http.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
set beresp.do_gzip = false;
}
else {
set beresp.do_gzip = true;
set beresp.http.X-Cache = "ZIP";
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment