大网数据广告活动
网站运营与故障问答

HTTP2 is enabled and working, but PHP $_SERVER['SERVER_PROTOCOL'] still says "HTTP/1.1"

· 52CE 我爱测

I've been migrating to a new host (AWS Lightsail with a Ubuntu instance) and while everything is working just fine I'm running into a quirk that I can't quite figure out. I've enabled HTTP2 on my virtual server and confirmed that…

问题原文

原帖链接 · GreatBlakes · CC BY-SA 4.0

I've been migrating to a new host (AWS Lightsail with a Ubuntu instance) and while everything is working just fine I'm running into a quirk that I can't quite figure out.

I've enabled HTTP2 on my virtual server and confirmed that files are using that protocol (via DevTools and http2.pro):

For reference, here is my server showing the Apache HTTP2 mod is enabled (and I did restart apache afterwords)

However, in PHP when I output $_SERVER['SERVER_PROTOCOL'] on my server it is still showing "HTTP/1.1":

But this same exact software (WordPress theme) on other servers is showing "HTTP/2.0" correctly:

I believe I have my Apache2 conf files setup correctly:

Port 443:

<VirtualHost *:443>
    Protocols h2 h2c http/1.1

and just to be thorough I did Port 80 as well:

<VirtualHost *:80>
    Protocols h2 h2c http/1.1

Unfortunately I do not have access to the conf files (or ssh) on the server that is working, so I can't cross-reference those files.

I've been reading a bunch of tutorials on HTTP2 to see if there is any additional setting or configuration that I may have missed, but most are showing the same instructions that I've implemented.

Can anyone point me in the right direction as to why this PHP "detection" is incorrectly displaying the protocol, or if there is something I missed that is preventing PHP from using HTTP2 in this one situation?

已采纳解答

原帖链接 · GreatBlakes · CC BY-SA 4.0

This has to do with how Cloudflare connects to servers. Although it does serve the client via HTTP2 (or HTTP3), it still connects to the server itself via HTTP1.1.

Cloudflare only uses HTTP/1.x between the origin web server and Cloudflare.

https://support.cloudflare.com/hc/en-us/articles/200168076-Are-the-HTTP-2-or-SPDY-protocols-supported-between-Cloudflare-and-the-origin-server-#6ncFUWOVRaVtPzYN1euBIC

This particular post helped illuminate the issue for me: https://community.cloudflare.com/t/passing-the-correct-server-protocol-to-the-origin/82386

I wish Cloudflare made it more obvious on their HTTP/2 Network setting that this was the case...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-07-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。