开启apache服务器gzip压缩

  1. 找到并打开apache/conf目录中的httpd.conf文件

    httpd.conf中打开deflate_Module和headers_Module模块,具体做法为将 如下两句前面的#去掉:

    LoadModule deflate_module modules/mod_deflate.so

    LoadModule headers_module modules/mod_headers.so

    在httpd.conf文件底部加入如下代码配置需要压缩的文件:

    <IfModule deflate_module>
    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
    </IfModule>

 

点赞