You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome报ERR_HTTP2_PROTOCOL_ERROR而Firefox正常的Nginx配置问题

问题背景

使用Vagrant搭建的开发环境运行Nginx、FPM与PHP 8,站点在HTTP1.1下运行正常,在Nginx配置中启用HTTP2后出现浏览器兼容性问题:

  • Chrome访问时报ERR_HTTP2_PROTOCOL_ERROR错误:
    Chrome报错
  • 相同页面在Firefox中可正常返回200状态码,且HTTP2协议生效:
    Firefox正常

移除Nginx配置中的http2指令后,所有浏览器访问功能恢复正常。

相关Nginx配置
server {
  listen 127.0.0.1:9080;
  server_name localhost DOMAIN;
  root /var/www/techship/public;

  access_log /var/www/techship/log/access.log;
  client_max_body_size 1G;

  expires 0;

  location ~ \..*/.*\.php$ {
    return 403;
  }

  location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 0;
    try_files $uri $1.$3;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/run/php/php8.0-fpm.sock;
  }
}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name DOMAIN;

  ssl_certificate certificates/dev.techship.crt;
  ssl_certificate_key certificates/dev.techship.key;

  ssl_session_timeout 1h;
  ssl_session_cache shared:SSL:16m;

  ssl_protocols TLSv1.3;
  ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;

  client_max_body_size 1G;

  expires 0;

  location / {
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Client-Verify SUCCESS;
    proxy_set_header X-SSL-Subject $ssl_client_s_dn;
    proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
    proxy_set_header HTTPS on;

    proxy_pass http://127.0.0.1:9080;
  }
}
问题根因

经排查,问题核心是PHP后端错误设置了名为Last Modified的响应头,符合HTTP规范的响应头名称应为Last-Modified。
HTTP/2协议对响应头的格式校验要求远严格于HTTP/1.1,Chrome对不符合规范的响应头校验规则更严格,识别到非法格式的响应头后直接断开连接抛出协议错误;Firefox对这类非标准响应头的容错性更高,会自动兼容处理,因此可以正常加载页面。


内容的提问来源于stack exchange,提问作者asegestam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 00:09:03