HTTP2 可用,但服务器拒绝使用它,为啥会这样?
Posted
技术标签:
【中文标题】HTTP2 可用,但服务器拒绝使用它,为啥会这样?【英文标题】:HTTP2 is available but server refuses to use it why it may be?HTTP2 可用,但服务器拒绝使用它,为什么会这样? 【发布时间】:2018-08-16 14:00:21 【问题描述】:我已经成功地为我的虚拟主机设置了 http2,但是当我尝试通过 curl 访问 url 时,看起来服务器拒绝通过 http2 进行连接并接受 http1。谁能解释为什么会这样?以及如何告诉我的服务器首先使用 http2。
以下是我尝试为其配置 http2 的站点的 curl 输出。
* Rebuilt URL to: https://example.com/
* Trying 172.24.112.31...
* TCP_NODELAY set
* Connected to example.com (172.24.112.31) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
[5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
[221 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
[112 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
[2426 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
[300 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
[4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
[37 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
[1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
[16 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
[16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: OU=Domain Control Validated; CN=*.example.com
* start date: Jun 9 09:24:31 2016 GMT
* expire date: Jun 10 09:24:31 2019 GMT
* subjectAltName: host "example.com" matched cert's "*.example.com"
* issuer: C=BE; O=GlobalSign nv-sa; CN=GlobalSign Domain Validation CA - SHA256 - G2
* SSL certificate verify ok.
[5 bytes data]
> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/7.58.0
> Accept: */*
>
[5 bytes data]
< HTTP/1.1 302 Found
< Date: Thu, 08 Mar 2018 08:54:23 GMT
< Server: Apache/2.4.29 (Ubuntu)
< Location: https://example.com
< Content-Length: 315
< Content-Type: text/html; charset=iso-8859-1
<
[315 bytes data]
* Connection #0 to host example.com left intact
以下两行是我的重点,
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
即使 http2 可用,服务器也不使用它,而是使用 http1.1。 请帮助我理解这一点并正确配置http2。
谢谢!
【问题讨论】:
这是一个 apache 配置问题,所以你可能应该展示它而不是 curl 调用... ***.com/a/54720367/4050261 这对我有帮助 【参考方案1】:我在 Internet 上找到了解决方案,我正在更新它以帮助遇到同样问题的人。当我检查 apache 错误日志文件时,我发现了一个类似于...的警告。
[http2:warn] [pid 8494] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
然后经过一个小时的谷歌搜索,我知道这是在 apache 上配置 HTTP2.0 时 prefork 模块的问题。您可以在 location. 找到有关此特定问题的更多信息以及配置 http2 的详细步骤。
如果您不想在配置http2时遇到任何麻烦,我希望this document能帮到您。
我遵循了这些步骤,我的问题得到了解决。
【讨论】:
以上是关于HTTP2 可用,但服务器拒绝使用它,为啥会这样?的主要内容,如果未能解决你的问题,请参考以下文章