在HTTPD主配置文件中添加如下,并确保deflate模块是启用的

#vim /etc/httpd/conf/httpd.conf

SetOutputFilter DEFLATE//调用一个叫DEFLATE输出过滤器

# mod_deflate configuration

# Restrict compression to these MIME types

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/x-javascript

AddOutputFilterByType DEFLATE text/javascript

AddOutputFilterByType DEFLATE text/css

# Level of compression (Highest 9 - Lowest 1)

DeflateCompressionLevel 9//过滤时压缩比

# 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 \bMSI[E] !no-gzip !gzip-only-text/html

然后#service httpd reload

#cp /etc/rc.d/rc.sysinit /vhosts/web1/htdocs/test.html     //vhosts/web1/htdocs这个目录是提前创建的

#curl -I http://192.160.108.160/test.html  //查看响应报文的首部

使用mod_deflate模块压缩页面优化传输速度-LMLPHP

#curl -I --compressed http://192.160.108.160/test.html

使用mod_deflate模块压缩页面优化传输速度-LMLPHP

可以看出调用的压缩功能以后,响应报文首部的内容长度是原来的三分之一

05-11 10:48