用于Brotli压缩的Nginx 模块

・6 分钟阅读

  • 源代码名称: ngx_brotli
  • 源代码网址: https://www.github.com/google/ngx_brotli
  • ngx_brotli的文档
  • ngx_brotli的源代码下载
  • Git URL:
    git://www.github.com/google/ngx_brotli.git
  • Git Clone代码到本地:
    git clone https://www.github.com/google/ngx_brotli
  • Subversion代码到本地:
    $ svn co --depth empty https://www.github.com/google/ngx_brotli
                              Checked out revision 1.
                              $ cd repo
                              $ svn up trunk
              
  • ngx_brotli

    Brotli是一种通用的无损压缩算法,它使用LZ77算法的现代变体,霍夫曼编码和二阶上下文建模的组合来压缩数据,它压缩比与当前可用的最佳通用压缩方法相当。 它的速度与deflate速度相似,但是,压缩程度更高。

    ngx_brotli是两个 Nginx 模块的集合:

    • ngx_brotli过滤模块- 用于响应动态压缩,
    • ngx_brotli static 模块- 用于预压缩文件。

    状态

    Brotli库和 Nginx 模块均处于活动状态。

    安装

    
    $ cd nginx-1.x.x
    
    
    $./configure --add-module=/path/to/ngx_brotli
    
    
    $ make && make install
    
    
    
    

    配置指令

    brotli_static

    • 语法: brotli_static on|off|always
    • 默认: off
    • 上下文: httpserverlocation

    启用或者禁用 .br 扩展的预压缩文件存在性检查。 always ,在所有情况下都使用预压缩文件,而不检查客户端是否支持它。

    brotli

    • 语法: brotli on|off
    • 默认: off
    • 上下文: httpserverlocationif

    启用或禁用响应的动态压缩。

    brotli_types

    • 语法: brotli_types <mime_type> [..]
    • 默认: text/html
    • 上下文: httpserverlocation

    对指定MIME类型的响应启用on-the-fly压缩,除了 text/html 之外。 特殊值 * 与任何MIME类型匹配。 使用 text/html MIME类型的响应始终被压缩。

    brotli_buffers

    • 语法: brotli_buffers <number> <size>
    • 默认: 32 4k|16 8k
    • 上下文: httpserverlocation

    设置用于压缩响应的缓冲区的numbersize。 默认情况下,缓冲区大小等于一个内存页。 这是 4k 或者 8k,具体取决于平台。

    brotli_comp_level

    • 语法: brotli_comp_level <level>
    • 默认: 6
    • 上下文: httpserverlocation

    设置Brotli质量( 压缩) level。 可以接受的值在从 011的范围内。

    brotli_window

    • 语法: brotli_window <size>
    • 默认: 512k
    • 上下文: httpserverlocation

    Sets Brotli size。Acceptable。4k8k64k32k。。8m16m

    brotli_min_length

    • 语法: brotli_min_length <length>
    • 默认: 20
    • 上下文: httpserverlocation

    设置将被压缩的响应的最小 length。 长度仅由 Content-Length 响应头字段确定。

    变量

    $brotli_ratio

    实现压缩比,以原始响应大小和压缩响应大小之间的比率计算。

    请参见捐赠。

    许可证

    
    Copyright (C) 2002-2015 Igor Sysoev
    
    
    Copyright (C) 2011-2015 Nginx, Inc.
    
    
    Copyright (C) 2015 Google Inc.
    
    
    All rights reserved.
    
    
    
    Redistribution and use in source and binary forms, with or without
    
    
    modification, are permitted provided that the following conditions
    
    
    are met:
    
    
    1. Redistributions of source code must retain the 上面 copyright
    
    
     notice, this list of conditions and the following disclaimer.
    
    
    2. Redistributions in binary form must reproduce the 上面 copyright
    
    
     notice, this list of conditions and the following disclaimer in the
    
    
     documentation and/or other materials provided with the distribution.
    
    
    
    THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
    
    
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    
    
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    
    
    ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
    
    
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    
    
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    
    
    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    
    
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    
    
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    
    
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    
    
    SUCH DAMAGE.
    
    
    
    
    讨论
    Fansisi profile image