Apache HTTP2 h2c模式无法正常工作

问题描述 投票:0回答:1

我想在apache上启用h2c模式,因此我可以使用HTTP2.0协议。在我的虚拟主机配置中,我包括以下行:

Protocols h2c http/1.1

我也遵循了advise to disable prefork,但是它没有按预期工作。

当前,我正在Ubuntu上使用apache 2.4.29。

案例1)curl请求http2升级

$ curl -vs --http2 http://domain1.com
* Rebuilt URL to: http://domain1.com/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to domain1.com (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: domain1.com
> User-Agent: curl/7.58.0
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
> 
< HTTP/1.1 101 Switching Protocols
< Upgrade: h2c
< Connection: Upgrade
* Received 101
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=28
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200 
< date: Sun, 00 Jan 1900 00:00:00 GMT
< server: Apache/2.4.29 (Ubuntu)
< last-modified: Fri, 29 Mar 2019 13:52:29 GMT
< etag: W/"2aa6-5853bfb4c71ac"
< accept-ranges: bytes
< content-length: 10918
< vary: Accept-Encoding
< content-type: text/html
< 
.... [snip website code] ....

案例2)curl直接使用http2

$ curl -vs --http2-prior-knowledge http://domain1.com
* Rebuilt URL to: http://domain1.com/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to domain1.com (127.0.0.1) port 80 (#0)
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5604f1cb1580)
> GET / HTTP/2
> Host: domain1.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
* http2 error: Remote peer returned unexpected data while we expected SETTINGS frame.  Perhaps, peer does not support HTTP/2 properly.

您可以看到案例1的运行正常,但是案例2并未返回该站点。为什么会这样呢?是因为Apache在没有安全性的情况下限制了HTTP2.0的直接使用吗?

希望您能给我答案,因为我不知道为什么现在无法正常工作。

apache http2
1个回答
0
投票

我想我已经找到了答案,并且我认为这是最新的Apache版本中的错误。如果仅在虚拟主机中启用h2c,则错误仍然存​​在,但是如果在默认虚拟主机(000-default.conf)上启用它,则一切似乎都正常。

我已经测试过并且正在起作用的另一个潜在解决方案是通过修改mods-enabled/http2.load文件在每个虚拟主机中启用协议h2和h2c:

LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so

<IfModule http2_module>
   Protocols h2 h2c http/1.1
</IfModule>

上面提到的任何选项似乎都能使系统在协议协商和先验知识下都能按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.