Apache开启Gzip压缩

作者 : admin 于 2008-10-28 13:57:00 标签: , ,
2008
10-28

文档位置 http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_deflate.html

Apache2中的实时压缩解压的模块编译在mod_deflate模块中,替换了原来的mod_gzip模块。

编译apache的时候 –enable-deflate  这个参数是默认开启的,编译完会有mod_deflate模块。

配置站点:

如果我们想使一个文件传输的时候进行加密,我们在站点配置文件里增加这样的配置

<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
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</Location>
这样,/opt/httpd-2.2.9/htdocs目录下的所有mime类型为text/html的文件就可以启用

未压缩的http头

Date Tue, 28 Oct 2008 13:04:15 GMT
Server Apache/2.2.9 (Unix) DAV/2 PHP/5.2.6
Last-Modified Tue, 28 Oct 2008 12:51:52 GMT
Etag “30623-55fda-45a4fb62a8a00″
Accept-Ranges bytes
Content-Length 352218
Content-Type text/html
Vary Accept-Encoding,User-Agent

压缩后的http头

Date Tue, 28 Oct 2008 13:07:39 GMT
Server Apache/2.2.9 (Unix) DAV/2 PHP/5.2.6
Last-Modified Tue, 28 Oct 2008 12:51:52 GMT
Etag “30623-55fda-45a4fb62a8a00″-gzip
Accept-Ranges bytes
Vary Accept-Encoding,User-Agent
Content-Encoding gzip
Content-Length 2778
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html

原来length为352218,压缩后为2778,效果还是很明显的。

不过对于length很小的文件,是不进行压缩的。

具体的一些调整的细节,可以看原apache手册。

发表评论




XHTML:你可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(若看不到验证码,请重新加载页面。)