为 Apache2 + FastCGI 设置启用数据压缩 [英] Enabling data compression for Apache2 + FastCGI setup

查看:30
本文介绍了为 Apache2 + FastCGI 设置启用数据压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与我之前的帖子有关:Android ICS 的 CSS 加载问题.

This Question is Related to my earlier post here: CSS loading issue with Android ICS.

我在Android ICS 的默认和Dolphin 浏览器的CSS 和JS 渲染问题.此内容由我服务器的后端引擎提供,该引擎使用 (Apache2 + FastCGI + Python) 设置.

Where I was facing issue with CSS and JS rendering by Android ICS's default and Dolphin browser. This content is served from my Server's Backend Engine, Which uses (Apache2 + FastCGI + Python) setup.

在寻找可能的问题时,我发现问题的主要原因是,内容不是从服务器以压缩形式发送的.

While searching for possible problems, I found that main cause for problem was, content was NOT sent in compressed form from Server.

因此示例响应标题如下所示:

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

和如果从平面文件提供相同的内容.响应标头如下所示.所有浏览器都能正确呈现.

and If Same content is served from flat file. Response header looks something as below. Which is rendered properly by all Browsers.

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 Browser 无法呈现内容(特别是 css、js 内容).它适用于所有其他浏览器.

and Some How, Android ICS's default and dolphin Browser are not able to render the content (Specially css, js content). It works with all other Browsers.

但本质上,后端引擎也存在一些问题,因为发送的是未压缩的数据.在响应标头中,这里有几个有趣的点:

But Essentially, there is some problem with Backend engine also because of which uncompressed data is sent. There are few Interesting points here to look, in Response header:

  1. 响应标头包含显示Content-Encoding gzip"的字段
  2. 但 Content-Length 显示的是资源未压缩版本的长度.

为了解决这个问题,我尝试了架构中的一些小改动,在我认为可能是问题原因的地方.我注意到,用 CGI 替换 fastCGI 解决了我的问题,现在数据以压缩格式发送.

To solve the problem I tried few small changes in Architecture, in places where I thought could be a problem cause. I noticed, replacing the fastCGI by CGI solved my Problem and data is sent in Compressed Format now.

虽然问题解决了,但我绝对想用fastCGI.所以我正在寻找可以解决问题的可能的配置更改.我在服务器的 Apache 设置中做了以下安排:

Though the problem is solved but I definitely want to use fastCGI. So I am looking for possible configuration changes that can solve Problem. I have done following Arrangements in Server's Apache settings:

  1. 从可用的 Apache 模块中启用 deflate 模块.
  2. 我的 /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 与我的脚本一起工作.

  • I have following lines to make fastCGI work with my script in /etc/apache2/sites-enabled/default file.

    <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 启用压缩时缺少什么吗?

    推荐答案

    最后,我在这里找到了问题的解决方案:http://wiki.catalystframework.org/wiki/deployment/apache_fastcgi

    Finally, I was able to find the solution of problem here: http://wiki.catalystframework.org/wiki/deployment/apache_fastcgi

    在这里,对于一个问题的回答:为什么我的应用程序如此缓慢,提供空白页面,和/或动作不快?在常见问题部分,他们清楚地说明了这一点.

    Here, For answer of a Question: Why is my application so slow, serving blank pages, and/or acting unexpededly? in FAQ section, they clearly say that.

    mod_fastcgimod_deflate 在某些版本下不能很好地共存apache(例如Debian Lenny 股票包).解决方法是不加载 deflate 模块.另一种解决方案是构建并安装 mod_fastcgi 的最新快照版本(可在http://www.fastcgi.com/dist/).

    mod_fastcgi and mod_deflate do not coexist well under certain versions of apache (Debian Lenny stock packages for example). A workaround is to not load the deflate module. An alternative solution is to build and install a recent snapshot version of mod_fastcgi (found at http://www.fastcgi.com/dist/).

    因此,按照帖子中的建议,我更新了服务器上的 libapache2-mod-fastcgi 包,现在我在客户端获取了具有正确响应标头值的压缩数据.

    So as suggested on post, I updated libapache2-mod-fastcgi package on Server and now I am getting compressed data at client side with correct Response header values.

    这篇关于为 Apache2 + FastCGI 设置启用数据压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆