Reputation: 11
I have multiple tomcat 7.0.56 running on CentOS 6 and a Varnish 4 running on another server Centos. Varnish has to do two important things for us: be a reverse proxy (works like a charm) and compress all data that can be compressed. We don't care about caching in our architecture. On the second point we have a problem. Varnish gzip CSS and JS and don't gzip html. In my default.vcl I do not compress files like pictures,swf or my pages designed for mobile and I set beresp.do_gzip true for all other stuff.
My vcl_recv :
sub vcl_recv {
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$" || req.url ~ "Mobile\.") {
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 {
# unkown algorithm
unset req.http.Accept-Encoding;
}
}
set req.backend_hint = h.backend(client.identity);
}
My vcl_backend_response:
sub vcl_backend_response {
if (beresp.http.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$" || beresp.http.url ~ "Mobile\.") {
set beresp.do_gzip = false;
}
else {
set beresp.do_gzip = true;
set beresp.http.X-Cache = "ZIP";
}}
All streams passing by Varnish are correctly gzipped except html pages. But these pages have headers almost correct.
Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Cookie:JSESSIONID=F116C2729E96D2150EEEACEB90F95EA9.node1; UUID=631a2947-14ac4e00ca6-0233de72a654bb34bce4a88d9e172e25
Host:tomcat.domain.tld
Pragma:no-cache
Referer:http://tomcat.domain.tld/path/to/ServletControl?sourceview=liste_menu
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Response Headers
Accept-Ranges:bytes
Age:0
Cache-Control:no-store,no-cache
Connection:keep-alive
Content-Language:fr-FR
Content-Type:text/html;charset=UTF-8
Date:Wed, 07 Jan 2015 14:55:04 GMT
Expires:0
MII:1800
Pragma:no-store,no-cache
Server:Apache-Coyote/1.1
Set-Cookie:UUID=631a2947-...e25; Version=1; Max-Age=10000; Expires=Wed, 07-Jan-2015 17:41:44 GMT; Path=/gce162
Transfer-Encoding:chunked
Vary:Accept-Encoding
Via:1.1 varnish-v4
X-Cache:ZIP
X-Varnish:163870
We can see the tag X-Cache with the value ZIP, the tag Vary with accept-Encoding but no Content-Encoding "gzip". So I don't understand why varnish don't gzip html and write the tag Vary=accept-Encoding ?
Any help is welcome. Thank you.
Baddou
Upvotes: 1
Views: 2527
Reputation: 1207
Believe it's related to Transfer-Encoding:chunked
response header be returned due to the content-length not being set for the html files.
To disable the chunked response, try adding set beresp.do_esi = true;
in the else loop of the vcl_backend_response.
see also
https://www.varnish-cache.org/trac/ticket/1506 and How do I disable 'Transfer-Encoding: chunked' encoding in Varnish?
Upvotes: 0