-
-
Save wpsmithtwc/bde757afb72b3a2abd6d0f7f8249bbbe to your computer and use it in GitHub Desktop.
Enable gzip compression in Varnish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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