WebSockets在GCP中与HTTP/2负载均衡器后端不起作用。

huangapple go评论59阅读模式
英文:

WebSockets not working with HTTP/2 Load Balancer backend in GCP

问题

我在Google Cloud Platform中的负载均衡器后面运行了一个应用程序。

当我在后端使用HTTPS协议时,我能够与WebSockets建立连接,所有WebSocket连接都正常工作。然而,当我将后端协议更改为HTTP/2时,我无法从应用程序连接,并返回502 Bad Gateway的响应。

我是否可以在HTTP/2中使用WebSockets,或者是否需要进行一些配置以在HTTP/2后端中使用WebSockets?

英文:

I have an application running behind a Load Balancer in Google Cloud Platform.

When I use the HTTPS protocol in the backend, I'm able to connect with WebSockets and all WebSocket connections work fine. However, when I change the backend protocol to HTTP/2, I'm unable to connect from the application, and it returns a response of 502 Bad Gateway.

Can I use WebSockets with HTTP/2, or do I need to perform some configuration in order to use WebSockets with an HTTP2 backend?

答案1

得分: 2

如其他人已经评论过的,WebSockets在HTTP/2中不受支持,这就是你收到5XX错误的原因。

话虽如此,WebSocket功能在HTTP/2中是可实现的(并得到改进)ref

如果你已经有使用WebSocket的现有代码,重写后端和前端可能不是一个好主意。

然而,如果你正在开发一个新的异步服务,那么建议考虑一下HTTP/2 + 服务器推送事件(Server Sent Event,SSE)方案。

英文:

As others have commented, WebSockets are not supported in HTTP/2 and this is the reason why you receive the 5XX error.

Having said that, the WebSocket functionality is achievable (and improved) with HTTP/2 ref.

If you have existing code working with WebSocket it might not be great to rewrite both backend and frontend.

However, if you are developing a new asynchronous service, it is a good idea to take a look at the HTTP/2 + Server Sent Event (SSE) scheme.

huangapple
  • 本文由 发表于 2020年1月6日 18:31:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610475.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定