基于httpd的mod_deflate模块
1、作用节约带宽,额外消耗CPU;部分老浏览器不支持;
压缩适于压缩的资源,例如文本文件;
2、涉及模块
LoadModule deflate_module modules/mod_deflate.so(CentOS6默认启用)
3、配置(httpd-2.2)
~]# vim /etc/httpd/conf.d/mod_deflate.conf
输入以下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
SetOutputFilter 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 6
# 压缩级别根据CPU消耗和带宽来决定,6为默认
# 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 no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
~]# httpd -t
~]# service httpd reload
4、确认压缩效果
配置前
配置后
页:
[1]