我有一个Apache 2.2.15实例作为代理在Red Hat 6.4上的Tomcat应用程序前面。我正在尝试配置Apache实例以向客户端gzip某些(列出白名单的内容类型)响应。 Apache正在使用mod_jk连接到Tomcat(尽管在使用mod_proxy时存在相同的问题,所以我认为我的问题与mod_jk或Tomcat无关)。mod_deflate gzip对MIME类型的响应,它不应该gzip
我有这个非常简单的mod_deflate模块配置:
AddOutputFilterByType DEFLATE text/html
这导致text/html
反应如预期需要用gzip压缩。但是,当我尝试下载由Tomcat生成的文件时,例如与内容类型application/vnd.ms-excel
电子表格,这些文件也被gzip压缩:
这里直接从Tomcat下载文件时是响应头:
Cache-Control:max-age=0
Content-Disposition:attachment; filename="file-20130322-104702.xls";
Content-Length:699904
Content-Type:application/vnd.ms-excel
Date:Fri, 22 Mar 2013 08:47:02 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:public
Server:Apache-Coyote/1.1
Set-Cookie:fileDownloadToken=true; Path=/
而且这是通过Apache下载文件时:
Cache-Control:max-age=0
Connection:Keep-Alive
Content-Disposition:attachment; filename="file-20130322-104524.xls";
Content-Encoding:gzip
Content-Type:application/vnd.ms-excel
Date:Fri, 22 Mar 2013 08:45:24 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Keep-Alive:timeout=30, max=100
Pragma:public
Server:Apache-Coyote/1.1
Set-Cookie:fileDownloadToken=true; Path=/
Transfer-Encoding:chunked
Vary:Accept-Encoding
我不明白为什么mod_deflate是gzipping这个响应(上面)?
在注释掉行AddOutputFilterByType DEFLATE text/html
后,文件不再被gzip压缩,所以我确定它是触发mod_deflate的那一行。内容类型为application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
以及其他可能的文件下载也存在同样的问题。然而,下载从Tomcat(通过Apache)的JavaScript文件,是不是gzip压缩(按预期的内容类型不匹配的规则):
Accept-Ranges:bytes
Cache-Control:PUBLIC, max-age=28800, must-revalidate
Connection:Keep-Alive
Content-Length:5578
Content-Type:application/javascript
Date:Fri, 22 Mar 2013 09:09:35 GMT
ETag:W/"5578-1362994418000"
Expires:Fri, 22 Mar 2013 17:09:35 GMT
Keep-Alive:timeout=30, max=100
Last-Modified:Mon, 11 Mar 2013 09:33:38 GMT
Server:Apache-Coyote/1.1
是mod_deflate模块的gzip这些电子表格的事实是,因为有问题它会导致响应被缓冲,触发分块编码,这是我不想要的,因为我希望浏览器显示进度监视器(这些可能是非常大的文件)。
任何想法?