1、作用
节约带宽,额外消耗CPU;部分老浏览器不支持;
压缩适于压缩的资源,例如文本文件;
2、涉及模块
LoadModule deflate_module modules/mod_deflate.so(CentOS6默认启用)
3、配置(httpd-2.2)
~]# vim /etc/httpd/conf.d/mod_deflate.conf
输入以下代码
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[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
~]# httpd -t
~]# service httpd reload
4、确认压缩效果
配置前
配置后
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。