Nginx开启 trim 和 brotli 压缩

  • openresty 添加trim压缩
    • 下载 Tengine ,解压后,找到源码包modulesnginx_http_trim_filter
    • 下载对应版本的openresty 源码包,重新编译(本步骤参考oneinstack)
        ./configure --prefix=/usr/local/openresty --user=www --group=www --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.1.1j --with-pcre=../pcre-8.44 --with-pcre-jit --with-ld-opt='-ljemalloc -Wl,-u,pcre_version' --add-module=/root/tengine-2.3.2/modules/ngx_http_trim_filter_module
        make -j 32
    • 完成上述步骤后,不需要 make install ! 找到 build/nginx-1.19.3/objs/nginx 将该执行文件替换原nginx (/usr/local/openresty/nginx/sbin/nginx)

  • nginx开启 Brotli压缩
    • git clone https://github.com/google/ngx_brotli
    • cd ngx_brotli
    • git submodule update –init
    • 参考上面的 trim 模块安装命令,增加(--add-module=/path/to/ngx_brotli)
      # 配置段: http, server, location
      
      # 开启 ngx_brotli 压缩
      brotli        on;
      
      # 指定压缩数据的最小长度,只有大于或等于最小长度才会对其压缩。这里指定 20 字节
      brotli_min_length  20;
      
      # Brotli 请求缓冲区的数量和大小
      brotli_buffers    16 10k;
      
      # Brotli 使用的窗口值。默认值为 512k
      brotli_window    512k;
      
      # 压缩水平可以是 0 到 11,默认值是 6。太高的压缩水平对性能提升并没有太大好处,因为这需要更多的 CPU 时间
      brotli_comp_level  6;
      
      # 指定允许进行压缩的回复类型
      brotli_types    text/html text/xml text/plain application/json text/css image/svg application/font-woff application/vnd.ms-fontobject application/vnd.apple.mpegurl application/javascript image/x-icon image/jpeg image/gif image/png;
      
      ### 可参考下面
      ### application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
      
      # 是否允许查找预处理好的、以 .br 结尾的压缩文件。可选值为 on、off、always
      brotli_static    always;

0 条评论