一聚教程网:一个值得你收藏的教程网站

热门教程

apache开启gzip压缩方法介绍

时间:2022-06-25 00:20:34 编辑:袖梨 来源:一聚教程网

第1步  httpd.conf中打开deflate_Module和headers_Module模块

 代码如下 复制代码

LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so

把前面的#号去掉,然后我们再在apache的httpd.conf中,加入下面代码

 代码如下 复制代码


SetOutputFilter DEFLATE
DeflateCompressionLevel 5
AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-

javascript

或直接这样也行

 代码如下 复制代码


    SetOutputFilter DEFLATE
    # Don’t compress images and other 
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary 
    SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary 
    SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary 
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css 
    AddOutputFilterByType DEFLATE application/x-javascript

我上面定写的就是一些常用的,如果大家有自己的其它格式文件我们加入进去就好了。


注意事项

mod_deflate是压缩模块,就是对要传输到客户端的代码进行gzip压缩;mod_headers模块的作用是告诉浏览器页面

使用了gzip压缩,如果不开启mod_headers那么浏览器就会对gzip压缩过的.页面进行下载

热门栏目