Nginx配置支持WebScoket 2022-02-17

最近测试将Blazor部署到Docker镜像,并使用Nginx进行集成,部署看上去没有问题,可在浏览器控制台发现如下问题:
Error: Failed to start the connection: Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
应该是Nginx的配置问题,解决方案是在Nginx的配置中设置如下参数:

  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";

这里的关键是将Connection 设置为 "upgrade"。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容