【发布时间】:2012-07-28 10:22:35
【问题描述】:
这个问题与我之前的帖子有关: CSS loading issue with Android ICS。
我遇到了Android ICS 的默认浏览器和 Dolphin 浏览器进行 CSS 和 JS 渲染的问题。此内容由我的服务器后端引擎提供,该引擎使用 (Apache2 + FastCGI + Python) 设置。
在搜索可能的问题时,我发现问题的主要原因是,内容不是从服务器以压缩形式发送的。
所以示例 Response Header 看起来如下:
Connection Keep-Alive
Content-Encoding gzip
Content-Length 5997
Content-Type text/css
Date Sun, 29 Jul 2012 14:29:08 GMT
Keep-Alive timeout=15, max=100
Server Apache (Ubuntu)
Vary Accept-Encoding
如果从平面文件提供相同的内容。响应标头如下所示。所有浏览器都正确呈现。
Accept-Ranges bytes
Connection Keep-Alive
Content-Encoding gzip
Content-Length 1430
Content-Type text/css
Date Sun, 29 Jul 2012 14:28:57 GMT
Etag "a9c06-176d-4c5e693c2a6c0"
Keep-Alive timeout=15, max=100
Last-Modified Sat, 28 Jul 2012 16:46:59 GMT
Server Apache (Ubuntu)
Vary Accept-Encoding
还有一些方法,Android ICS 的默认浏览器和 dolphin 浏览器无法呈现内容(特别是 css、js 内容)。它适用于所有其他浏览器。
但本质上,后端引擎也存在一些问题,因为发送了未压缩的数据。在响应标头中,这里有几个有趣的点:
- 响应标头包含“Content-Encoding gzip”字段
- 但 Content-Length 显示的是资源的未压缩版本的长度。
为了解决这个问题,我尝试了架构中的一些小改动,在我认为可能导致问题的地方。 我注意到,用 CGI 替换 fastCGI 解决了我的问题,现在数据以压缩格式发送。
问题
虽然问题解决了,但我肯定想使用fastCGI。所以我正在寻找可以解决问题的可能的配置更改。 我在服务器的 Apache 设置中做了如下安排:
- 从可用的 Apache 模块启用 deflate 模块。
-
我的
/etc/apache2/mods-enabled/deflate.conf文件包含以下文本:<IfModule mod_deflate.c> # these are known to be safe with MSIE 6 AddOutputFilterByType DEFLATE text/html text/plain text/xml # everything else may cause problems with MSIE 6 AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript AddOutputFilterByType DEFLATE application/rss+xml </IfModule> -
我有以下几行可以让我在
/etc/apache2/sites-enabled/default文件中的脚本使用fastCGI。<Files my_script_name.py> SetHandler fastcgi-script </Files> FastCgiServer /path_to_script/my_script_name.py -processes 4 -socket /tmp/my_script_name.sock
问题
我尝试了各种配置更改,但似乎都没有解决我的问题。 使用 fastCGI 启用压缩我这里有什么遗漏的吗?
【问题讨论】:
标签: android python apache2 gzip fastcgi