跳转至

unzstd:为不支持 zstd 的客户端解压 zstd 编码的响应

安装

您可以在任何基于 RHEL 的发行版中安装此模块,包括但不限于:

  • RedHat Enterprise Linux 7、8、9 和 10
  • CentOS 7、8、9
  • AlmaLinux 8、9
  • Rocky Linux 8、9
  • Amazon Linux 2 和 Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-unzstd
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-unzstd

通过在 /etc/nginx/nginx.conf 顶部添加以下内容来启用模块:

load_module modules/ngx_http_unzstd_filter_module.so;

本文档描述了 nginx-module-unzstd v0.2.0 ,发布于 2026 年 9 月 2 日。


server {
    listen 127.0.0.1:8080;
    server_name localhost;

    location / {
        # 为不支持 zstd 压缩的客户端启用 zstd 解压
        unzstd on;

        proxy_pass http://foo.com;
    }
}

指令

unzstd

语法: unzstd on | off;

默认值: unzstd off;

上下文: http、server、location、when

为不支持 zstd 的客户端启用或禁用 zstd 压缩响应的解压功能。 当使用 ngx_condition_module 构建时,此指令也可以配置在 when 块内。

unzstd_force

语法: unzstd_force on | off;

默认值: unzstd_force off;

上下文: http、server、location、when

启用后,无需检查客户端是否接受 zstd 即可解压 zstd 响应。 没有 Content-Encoding: zstd 的响应不受影响。 当使用 ngx_condition_module 构建时,此指令也可以配置在 when 块内。

unzstd_buffers

语法: unzstd_buffers number size;

默认值: unzstd_buffers 32 4k | 16 8k;

上下文: http、server、location

设置用于解压响应的缓冲区数量和大小。默认情况下,缓冲区大小等于一个内存页。 根据平台不同,该值可能是 4K 或 8K。

测试

快速测试套件会构建一个真实的动态模块,并使用 nginx.org 官方的 nginx-tests 测试框架运行它:

make tests

发布门禁还包括静态 ASan/UBSan 执行、详尽的 cppcheck、CodeQL、重命名模块加载、nginx -tnginx -T、恶意 客户端探测、重载和 worker 替换检查、稳定的文件描述符 计数,以及 schema-v1 Torture Lab 证据:

make lint
make tests-asan
make runtime

GitHub

您可以在 nginx-module-unzstd 的 GitHub 仓库 中找到 此模块的其他配置技巧和文档。