compression-vary: 增强的 Vary 头处理用于压缩
安装
您可以在任何基于 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-compression-vary
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-compression-vary
通过在 /etc/nginx/nginx.conf 的顶部添加以下内容来启用该模块:
load_module modules/ngx_http_compression_vary_filter_module.so;
本文档描述了 nginx-module-compression-vary v0.1.0,于 2026 年 1 月 6 日发布。
概述
server {
listen 127.0.0.1:8080;
server_name localhost;
location / {
gzip on;
compression_vary on;
proxy_pass http://foo.com;
}
}
指令
compression_vary
语法: compression_vary on | off;
默认值: compression_vary off;
上下文: http, server, location
启用或禁用在 gzip、gzip_static 或 gunzip 指令激活时插入 Vary: Accept-Encoding 响应头字段。
与 gzip_vary 不同,如果原始响应存在 Vary 头,它将把 Accept-Encoding 附加到原始 Vary 头中。此外,多个 Vary 头将合并为一个,并用逗号分隔。Vary 中的重复头值将被删除。
当激活来自第三方压缩模块的指令,例如 brotli、brotli_static、unbrotli、zstd、zstd_static 和 unzstd 时,此模块也有效。
GitHub
您可以在 nginx-module-compression-vary 的 GitHub 仓库 中找到此模块的其他配置提示和文档。