Skip to content

Instantly share code, notes, and snippets.

@TomCan
Created June 8, 2016 08:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TomCan/b44ee7e26afd7947f1aa66bd97e7a543 to your computer and use it in GitHub Desktop.
Save TomCan/b44ee7e26afd7947f1aa66bd97e7a543 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