• httpd.conf
LoadModule deflate_module modules/mod_deflate.so



<IfModule deflate_module> #或者<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE # 告诉 apache 对传输到浏览器的内容进行压缩
    DeflateCompressionLevel 9 # 压缩等级 1-9
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    #设置不对后缀gif,jpg,jpeg,png的图片文件进行压缩
</IfModule>
  • 指定文件格式压缩
<IfModule mod_deflate.c>
    # 压缩等级 9
    DeflateCompressionLevel 9
    # 压缩类型 html、xml、php、css、js
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascript application/x-httpd-php
    AddOutputFilter DEFLATE js css
</IfModule>