是否可以使用HAproxy代理传入的H2c请求?
我尝试了以下配置using this tutorial:
frontend receiver
mode http
bind *:80
bind *:443 ssl crt-list /some/file alpn h2,h2c,http/1.1
default_backend processor
此配置适用于h2(HTTP / 2安全)请求,并将HTTP / 1.1请求发送到后端。但是,它不适用于通过curl发出的h2c(HTTP / 2明文)请求。我收到以下错误消息:
$ curl --http2-prior-knowledge http://server.com/status
...
* 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 ...)
> GET /status HTTP/2
...
* http2 error: Remote peer returned unexpected data while we expected SETTINGS frame. Perhaps, peer does not support HTTP/2 properly.
...
curl: (16) Error in the HTTP2 framing layer
我怀疑这是因为HAProxy在响应中需要h2数据(而不是h2c)。 关于我需要更改HAProxy配置以支持传入的h2c请求的任何建议?
答案 0 :(得分:1)
如果后端服务器支持h2c,则可以以tcp
模式代理传入的请求。那就是您使用的教程对h2c所做的操作,但无缘无故也不适用于h2c。
由于该教程是HAProxy has added HTTP/2 support in v1.8编写的,因此它也可以在http
模式下代理h2请求,但是据我所知,对于h2c不可能这样做。该文档对此没有明确说明,但是确实使用状态ALPN来协商HTTP / 2,并且this question状态未添加h2c支持。
HAProxy 1.9 did add h2c support in the backend,但仍未注意到前端支持它。
说实话,前端的h2c支持通常用途有限,因为浏览器不支持它,并且因为它需要升级步骤或假设服务器支持它(两者都不理想),所以与h2不同可以作为TLS协商的一部分进行协商,而无需额外的往返行程或假设。
您是否需要在前端提供h2c支持的特定原因,因为可能有更好的方法来实现您想要的目标。
答案 1 :(得分:0)
基于HAproxy通道中的discussion,可以使用proto h2
上的bind
设置代理h2c请求。但是,当前不可能在相同端口上同时侦听HTTP / 1.1和HTTP / 2请求。
使h2c
在HAProxy上工作的示例配置:
frontend f_h2c
mode http
option http-use-htx
bind *:8080 proto h2
default_backend local_node
backend local_node
mode http
option http-use-htx
server localhost localhost:9090 proto h2