Nginx 安装 brotli 模块

Nginx 安装 brotli 模块

小小孩
2023-11-02 / 3 评论 / 209 阅读 / 正在检测是否收录...

前置条件

cd /www/server
git clone --recurse-submodules -j8 https://gitee.com/hipi/ngx_brotli.git
cd ngx_brotli/deps/brotli
mkdir out && cd out
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed ..
cmake --build . --config Release --target brotlienc
cd ../../../..

安装

方法 1

echo "--add-module=/www/server/ngx_brotli" > /www/server/panel/install/nginx_configure.pl

面板直接编译安装

方法 2

模块名称:ngx_brotli
模块描述:ngx_brotli
模块参数:--add-module=/www/server/ngx_brotli
前置脚本不填

log2v6b3.png

配置

# 启用 Brotli 压缩
brotli on;

# 设置 Brotli 压缩级别
brotli_comp_level 6;
  
# 设置启用压缩的最小文件大小
brotli_min_length 20;

# 配置 Brotli 压缩的缓冲区大小
brotli_buffers 16 8k;

# 指定要压缩的文件类型
brotli_types text/xml text/plain text/css application/javascript application/x-javascript application/rss+xml text/javascript image/tiff image/svg+xml application/json application/xml;
0

评论 (3)

取消
  1. 头像
    热心网友
    Windows 10 · Google Chrome

    感谢分享

    回复
  2. 头像
    空空裤兜
    Windows 10 · Google Chrome

    这个直接在CDN开启,不在源站添加,有效果吗

    回复
    1. 头像
      小小孩 作者
      MacOS · Google Chrome
      @ 空空裤兜

      也有效果的

      回复