2013-03-22 71 views
0

我有一個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這些電子表格的事實是,因爲有問題它會導致響應被緩衝,觸發分塊編碼,這是我不想要的,因爲我希望瀏覽器顯示進度監視器(這些可能是非常大的文件)。

任何想法?

回答

0

使用一個文件擴展名匹配添加的頭而不是:

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

每一個嘗試,並與效果最好的去。