• 2007-02-26

    apache2使用mod_deflate压缩网页

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://snk.blogbus.com/logs/4618071.html

    apache2已经用mod_deflate代替了mod_gzip

    apache2已经包含了mod_deflate

    打开模组
    httpd.conf添加
    LoadModule deflate_module modules/mod_deflate.so

    如果想只压缩html,text,xml 如果下面配置:
    AddOutputFilterByType DEFLATE text/html text/plain text/xml

    下面给出我的配置档:
    LoadModule deflate_module modules/mod_deflate.so

    <location />
    SetOutputFilter DEFLATE

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Don't compress images
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \
    \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \
    \.pdf$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \
    \.(css|js)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary

    </location>


    DeflateFilterNote Input input_info
    DeflateFilterNote Output output_info
    DeflateFilterNote Ratio ratio_info
    LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
    CustomLog logs/deflate_log.log deflate

    在apache的使用手册上还有这么一句,但是不知道为什么不能添加上去.
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary

    这个可以压缩 SVN 出来的文件。

    ---------------------------------------------

    不能添加的原因是下面的模组没有打开:

    LoadModule headers_module modules/mod_headers.so


    收藏到:Del.icio.us