apache增加mod_deflate压缩模块 – 杨思为 | 我们一家

来源:百度文库 编辑:神马文学网 时间:2024/04/19 18:53:41


mod_deflate是Apache2中的标准过滤器模块,该模块的功能与mod_gzip的功能一样:压缩网页各类组件,加快网页下载速度。

通常Apache2中增加增加模块都不需要重新编译Apache,只需要动态添加需要的模块就OK了。首先在Apache源安装文件夹的modules文件夹中查找到mod_deflate.c文件……

在Apache2.2.2中,mod_deflate模块在modules/filters文件夹中,确定位置后:

[root@localhost modules]# cd /apache-source-install-path/modules/filters

[root@localhost filters]# /apache-installed-path/bin/apxs -i -a -c mod_deflate.c

如果安装成功,则会提示:

chmod 755 /apache-installed-path/modules/mod_deflate.so
[activating module `deflate' in /apache-installed-path/conf/httpd.conf]

此时,打开/apache-installed-path/conf/httpd.conf文件,搜索“mod_deflate”,因该可以看到该模块已经加载上了,如下:

LoadModule deflate_module     modules/mod_deflate.so

既然模块加载上了,那么就可以对需要的内容进行压缩设置了。apache官方有详细的mod_deflate配置说明,以下是我对测试网站做的mod_deflate配置:


DeflateCompressionLevel 9   #压缩的级别设置为最高

#将html、文本、xml、php进行压缩
AddOutputFilterByType   DEFLATE text/html text/plain text/xml application/x-httpd-php

# 将html、htm、xml、php、css、js进行压缩
AddOutputFilter         DEFLATE  html  htm  xml  php  css  js

apache2增加mod_deflate压缩模块这样就OK了。当然啦,对httpd.conf做了以上修改,应该保存文件并且重启apache服务。这个时候再通过一些http观察软件查看页面到底有没有进行压缩。以下是我对西北大学测试网站启用mod_deflate进行压缩后的效果截图:

mod_deflate压缩结果

通过实验证明,启用Apache的mod_deflate模块进行网页内容压缩,能够平均将网页大小降到原来的60%左右。尤其是对非图片、非多媒体为主的网站效果更加明显。