千家信息网

基于httpd的mod_deflate模块

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,1、作用节约带宽,额外消耗CPU;部分老浏览器不支持;压缩适于压缩的资源,例如文本文件;2、涉及模块LoadModule deflate_module modules/mod_deflate.so(C
千家信息网最后更新 2025年01月20日基于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

输入以下代码

SetOutputFilter DEFLATE# 设置压缩过滤器,指明哪些类型适合压缩# mod_deflate configuration# Restrict compression to these MIME typesAddOutputFilterByType DEFLATE text/plainAddOutputFilterByType DEFLATE text/htmlAddOutputFilterByType DEFLATE application/xhtml+xmlAddOutputFilterByType DEFLATE text/xmlAddOutputFilterByType DEFLATE application/xmlAddOutputFilterByType DEFLATE application/x-javascriptAddOutputFilterByType DEFLATE text/javascriptAddOutputFilterByType 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 problemsBrowserMatch ^Mozilla/4\.0[678] no-gzip# MSIE masquerades as Netscape, but it is fineBrowserMatch \bMSIE !no-gzip !gzip-only-text/html


~]# httpd -t~]# service httpd reload



4、确认压缩效果

配置前

配置后






0