最近测试将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"。