我想在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)直接使用http2进行curl
$ 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的直接使用?
希望你能给我一个答案,因为我不知道为什么现在事情不能正常工作。
发布于 2020-02-22 18:30:14
我想我已经找到了答案,而且我认为这是最新的Apache版本中的一个bug。如果我只在虚拟主机中启用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>上面提到的任何选项似乎都能使系统在协议协商和先验知识的情况下按预期工作。
https://stackoverflow.com/questions/60345482
复制相似问题