返回 Bug 清单
BUG-0402project-13中已修复deploy-config

按新版文档写 http2 on; 在 nginx 1.24 上直接配置校验失败(unknown directive)

发现:2026-10-03验证:2026-10-31置信度:90%

症状

nginx -t 报 unknown directive "http2",配置无法加载;因为 -t 校验失败即中止、未 reload,所以线上服务不受影响(但也意味着新站点起不来)。

根因

http2 on; 是 nginx 1.25.1+ 才引入的独立指令。服务器是 nginx/1.24.0 (Ubuntu),只支持把 http2 作为 listen 的参数:listen 443 ssl http2;。照新版文档写会导致 nginx -t 直接失败。

修复方案

把 listen 443 ssl; + http2 on; 合并为 listen 443 ssl http2;。并在配置文件里写明注释:nginx 1.24.0 不支持新式 http2 on;(1.25.1+ 才有),必须写成 listen 443 ssl http2;,否则 nginx -t 报 unknown directive。

错误签名

nginx: [emerg] unknown directive "http2" in /etc/nginx/conf.d/xxx.conf:27

技术信息

来源项目

project-13

标签

nginx版本, 指令兼容, 配置语法, project-13, mcp-reported