Skip to content

Instantly share code, notes, and snippets.

@kevin39
Forked from TomCan/varnish.vcl
Created June 17, 2020 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevin39/d780b9eba6384ef3bc8fd5462d73ad49 to your computer and use it in GitHub Desktop.
Save kevin39/d780b9eba6384ef3bc8fd5462d73ad49 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