使用mod_deflate提升网页浏览的速度

字体大小: 中小 标准 ->行高大小: 标准

apache1.3.x可以用mod_gzip进行优化网页浏览的速度,可以明显的感觉到速度的提升。在apache2中也尝试用mod_gzip,但是配置后确发现网页不能正确显示(空白页),所以改换mod_deflate。

在Linux命令行下运行以下命令安装mod_deflate模块(斜体是apache2的目录)

/usr/local/apache2/bin/apxs -i -c /root/httpd-2.0.48/modules/filters/mod_deflate.c

编辑httpd.conf,加入以下内容:

LoadModule deflate_module modules/mod_deflate.so

DeflateFilterNote ratio
LogFormat '"%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" (%{ratio}n)' deflate

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch MSIE !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI
.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
# Header命令不对?注释这一行
# Header append Vary User-Agent env=!dont-vary
</Location>

#查找Customlog 注释原来的的一行,改成
CustomLog logs/deflate_log deflate

Boban <boban@21php.com > 写于2004年3月27日凌晨
附注:关于mod_deflate的详细内容,可以参考http://httpd.apache.org/docs-2.0/mod/mod_deflate.html

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/1156.html