使用mod_deflate提升网页浏览的速度 |
| 作者:佚名 来源:中文PHP网 作者: Boban 更新:2006-8-25 21:05:35 错误报告 我要投稿 |
|
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
#查看logs目录下deflate_log文件,你可以看到许多这样的信息: "www.21php.com 220.163.107.88 - - [27/Mar/2004:01:03:55 -0800] "GET /ad/usrlogo /21PHPLOGO_88X31.gif HTTP/1.1" 200 3656 "http://soft.ttee.com/vbb/" "Mozilla /4.0 (compatible; MSIE 5.5; Windows 98)"" (-) "www.21php.com 211.144.88.138 - - [27/Mar/2004:01:03:57 -0800] "GET /tutorial/t utorial.php?tid=68 HTTP/1.1" 200 5173 "http://www.21php.com/tutorial/tutorial. php?catalogid=12" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; . NET CLR 1.0.3705; Alexa Toolbar)"" (29) "www.21php.com 211.144.88.138 - - [27/Mar/2004:01:03:58 -0800] "GET /style.css HTTP/1.1" 304 - "http://www.21php.com/tutorial/tutorial.php?tid=68" "Mozilla /4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Alexa Tool bar)"" (-) "www.21php.com 211.144.88.138 - - [27/Mar/2004:01:03:58 -0800] "GET /images/bar -4.gif HTTP/1.1" 304 - "http://www.21php.com/tutorial/tutorial.php?tid=68" " Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Ale xa Toolbar)"" (-) "www.21php.com 211.144.88.138 - - [27/Mar/2004:01:03:58 -0800] "GET /images/log o.gif HTTP/1.1" 304 - "http://www.21php.com/tutorial/tutorial.php?tid=68" "M ozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Alex a Toolbar)"" (-) "www.21php.com 211.144.88.138 - - [27/Mar/2004:01:03:58 -0800] "GET /images/ico n1.gif HTTP/1.1" 304 - "http://www.21php.com/tutorial/tutorial.php?tid=68" " Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Ale xa Toolbar)"" (-)
Boban <boban@21php.com > 写于2004年3月27日凌晨 附注:关于mod_deflate的详细内容,可以参考http://httpd.apache.org/docs-2.0/mod/mod_deflate.html
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |