zoukankan      html  css  js  c++  java
  • apache 压缩 gzip

    配置

    编辑httpd.conf文件

    去掉 #LoadModule headers_module modules/mod_headers.so 前面的注释# 
    去掉 #LoadModule deflate_module modules/mod_deflate.so 前面的注释# 
    去掉 #LoadModule filter_module modules/mod_filter.so 前面的注释#

    第三个模块一定要打开,很多人根据网上的配置无法生效,就是这个模块没有开启。不开启的话下面配置后也无法启动Apache。

    然后在最底部添加如下代码

    <ifmodule mod_deflate.c>
    DeflateCompressionLevel 6
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/php
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/atom_xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/gif image/png  image/jpe image/swf image/jpeg image/bmp
    # Don’t compress images and other  #排除不需要压缩的文件
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4.0[678] no-gzip
    BrowserMatch MSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI .(?:html|htm)$ no-gzip dont-varySetEnvIfNoCase 
    #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
    </ifmodule>

    注:注释和命令不要写在同一行,不然容易导致Apache无法启动。网上很多教程都是写在同一行,也有这个问题我也找了很久,可能是我这的问题把。。

    运行

    用了一个文本做测试,大小是300左右。来看看压缩后多少~

    这里写图片描述

    压缩后:

    这里写图片描述

    大小是77kb。体积减少了将近 4倍。效果还是非常很可观的。文件越多效果越明显!!

  • 相关阅读:
    JAVA WEBSERVICE服务端&客户端的配置及调用(基于JDK)
    An internal error occurred during: "Launching New_configuration"
    Android 创建虚拟机时“提示no system images installed for this target”
    [转] 传说中的WCF(2):服务协定的那些事儿
    [转] 传说中的WCF
    python的包管理
    python入门常用方法(转json,模拟浏览器请求头,写入文件)
    python读写数据篇
    python跳坑手记
    python爬虫入门篇
  • 原文地址:https://www.cnblogs.com/whm-blog/p/8708113.html
Copyright © 2011-2022 走看看