首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache HTTP2 h2c模式不能正常工作

Apache HTTP2 h2c模式不能正常工作
EN

Stack Overflow用户
提问于 2020-02-22 04:00:05
回答 1查看 733关注 0票数 0

我想在apache上启用h2c模式,这样我就可以使用HTTP2.0协议了。在我的虚拟主机配置中,我包含了下面这行:

代码语言:javascript
复制
Protocols h2c http/1.1

我也关注了advise to disable prefork,但它并没有像预期的那样工作。

目前我在Ubuntu上使用的是apache 2.4.29。

案例1) curl请求http2升级

代码语言:javascript
复制
$ 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

代码语言:javascript
复制
$ 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的直接使用?

希望你能给我一个答案,因为我不知道为什么现在事情不能正常工作。

EN

回答 1

Stack Overflow用户

发布于 2020-02-22 18:30:14

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

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

代码语言:javascript
复制
LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60345482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档