我如何知道我的网站是通过 HTTP 还是 HTTP/2 提供服务?
How do I know if my website is being served over HTTP or HTTP/2?
是否有命令或服务可以告诉我我的网站是通过 HTTP 还是 HTTP/2 提供服务。
我找到了这个工具:HTTP/2 Test | A simple HTTP/2.0 test tool,但它只告诉我我的网站是否支持 HTTP/2,但不知道它是否已经在使用 HTTP/2。
这些也是这个 Chrome 扩展:HTTP/2 and SPDY indicator,它告诉我 HTTP/2 已经在我的网站上启用,但据我所知我的 Apache 版本没有'甚至都不支持。
有什么方法可以确定吗?谢谢!
Apache 不必支持它。 Chrome 扩展读取 HTTP headers 来确定。
另一种方法是在 Chrome 或 Firefox 中查看网络选项卡 > headers > 响应 headers > 查看源代码。可以看到 headers 。它应该是 "HTTP/2" 或者我现在想不起来的某种形式。
最简单:您可以使用 curl -I <your site>
,它将 HTTP 响应放在第一行。
HTTP/2.0 200
server:nginx
date:Fri, 29 Apr 2016 14:31:40 GMT
content-type:text/html; charset=utf-8
content-length:7629
last-modified:Thu, 07 Apr 2016 02:41:08 GMT
....
对于使用 Nginx 的人,您可以查看通常位于 /var/log/nginx/access.log
的访问日志,并查找像
这样的行
167.220.232.9 - - [12/Feb/2018:15:09:04 +0800] "GET / HTTP/2.0" 200 2546 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"
您也可以尝试 --http2
或 --http2-prior-knowledge
。这些将强制网站使用 HTTP/2.0:
来自 curl 手册:
--http2-prior-knowledge
(HTTP) Tells curl to issue its non-TLS HTTP requests using HTTP/2 without HTTP/1.1 Upgrade. It requires
prior knowledge that the server supports HTTP/2 straight away. HTTPS requests will still do HTTP/2 the
standard way with negotiated protocol version in the TLS handshake.
--http2-prior-knowledge requires that the underlying libcurl was built to support HTTP/2. This option
overrides --http1.1 and -0, --http1.0 and --http2. Added in 7.49.0.
--http2
(HTTP) Tells curl to use HTTP version 2.
See also --no-alpn. --http2 requires that the underlying libcurl was built to support HTTP/2. This option
overrides --http1.1 and -0, --http1.0 and --http2-prior-knowledge. Added in 7.33.0.
如果您还没有准备好访问 command-line 和 cURL,或者您正在浏览多个 CDN 层(例如,如果您的 HTTP/2由 CloudFlare 等提供商提供)。
- 打开 Chrome 开发工具 (Ctrl-Shift-I)
- 打开“网络”选项卡
- 如果您的页面已经加载,您可能需要刷新 (Ctrl-R)
- Right-click 在请求列表的 header 行(标记为:名称、方法、状态等的行)
- Select 上下文菜单中的协议。
- 您可能需要再次刷新(Ctrl-R),您会看到所有正在使用的协议。
如果您看到 h2
,那么恭喜您!您的网站正在 HTTP/2.
上提供服务
是否有命令或服务可以告诉我我的网站是通过 HTTP 还是 HTTP/2 提供服务。
我找到了这个工具:HTTP/2 Test | A simple HTTP/2.0 test tool,但它只告诉我我的网站是否支持 HTTP/2,但不知道它是否已经在使用 HTTP/2。
这些也是这个 Chrome 扩展:HTTP/2 and SPDY indicator,它告诉我 HTTP/2 已经在我的网站上启用,但据我所知我的 Apache 版本没有'甚至都不支持。
有什么方法可以确定吗?谢谢!
Apache 不必支持它。 Chrome 扩展读取 HTTP headers 来确定。
另一种方法是在 Chrome 或 Firefox 中查看网络选项卡 > headers > 响应 headers > 查看源代码。可以看到 headers 。它应该是 "HTTP/2" 或者我现在想不起来的某种形式。
最简单:您可以使用 curl -I <your site>
,它将 HTTP 响应放在第一行。
HTTP/2.0 200
server:nginx
date:Fri, 29 Apr 2016 14:31:40 GMT
content-type:text/html; charset=utf-8
content-length:7629
last-modified:Thu, 07 Apr 2016 02:41:08 GMT
....
对于使用 Nginx 的人,您可以查看通常位于 /var/log/nginx/access.log
的访问日志,并查找像
167.220.232.9 - - [12/Feb/2018:15:09:04 +0800] "GET / HTTP/2.0" 200 2546 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"
您也可以尝试 --http2
或 --http2-prior-knowledge
。这些将强制网站使用 HTTP/2.0:
来自 curl 手册:
--http2-prior-knowledge
(HTTP) Tells curl to issue its non-TLS HTTP requests using HTTP/2 without HTTP/1.1 Upgrade. It requires
prior knowledge that the server supports HTTP/2 straight away. HTTPS requests will still do HTTP/2 the
standard way with negotiated protocol version in the TLS handshake.
--http2-prior-knowledge requires that the underlying libcurl was built to support HTTP/2. This option
overrides --http1.1 and -0, --http1.0 and --http2. Added in 7.49.0.
--http2
(HTTP) Tells curl to use HTTP version 2.
See also --no-alpn. --http2 requires that the underlying libcurl was built to support HTTP/2. This option
overrides --http1.1 and -0, --http1.0 and --http2-prior-knowledge. Added in 7.33.0.
如果您还没有准备好访问 command-line 和 cURL,或者您正在浏览多个 CDN 层(例如,如果您的 HTTP/2由 CloudFlare 等提供商提供)。
- 打开 Chrome 开发工具 (Ctrl-Shift-I)
- 打开“网络”选项卡
- 如果您的页面已经加载,您可能需要刷新 (Ctrl-R)
- Right-click 在请求列表的 header 行(标记为:名称、方法、状态等的行)
- Select 上下文菜单中的协议。
- 您可能需要再次刷新(Ctrl-R),您会看到所有正在使用的协议。
如果您看到 h2
,那么恭喜您!您的网站正在 HTTP/2.