繁体   English   中英

mod_deflate对不应该gzip的MIME类型的gzips响应

[英]mod_deflate gzips responses for MIME types that it shouldn't gzip

我在Red Hat 6.4上的Tomcat应用程序前面有一个Apache 2.2.15实例作为代理。 我正在尝试将Apache实例配置为gzip对客户端的某些(列入白名单的内容类型)响应。 Apache正在使用mod_jk连接到Tomcat(尽管在使用mod_proxy时存在相同的问题,所以我认为我的问题与mod_jk或Tomcat没有关系)。

我有这个非常简单的mod_deflate配置:

AddOutputFilterByType DEFLATE text/html

这将导致text/html响应被按预期方式压缩。 但是,当我尝试下载由Tomcat生成的文件(例如,内容类型为application/vnd.ms-excel的电子表格)时,这些文件也会被压缩:

以下是直接从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将这个响应压缩(上方)?

在注释掉AddOutputFilterByType DEFLATE text/htmlAddOutputFilterByType DEFLATE text/html ,文件不再被压缩,因此我确定正是那行触发了mod_deflate。 对于内容类型为application/vnd.openxmlformats-officedocument.spreadsheetml.sheet文件下载,可能application/vnd.openxmlformats-officedocument.spreadsheetml.sheet出现同样的问题。 但是,并不会压缩从Tomcat(通过Apache)下载javascript文件的代码(这是预期的,因为内容类型与规则不匹配):

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压缩的事实是一个问题,因为它导致响应被缓冲,触发了分块编码,这是我不希望的,因为我希望浏览器显示进度监视器(这些文件可能确实很大)。

有任何想法吗?

使用文件扩展名匹配添加的头而不是:

<filesMatch "\.(html)$">
# Header set Content-Encoding x-deflate
# Header set Content-Encoding deflate
# Header set Content-Encoding gzip
</filesMatch>

尝试每一种,然后选择最有效的一种。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM