首页 > 解决方案 > 信号器在 WebSocket 握手期间不使用 https 错误:意外的响应代码:200

问题描述

我有后端,我将信号器用于 websocket。当客户端和后端在 http 上时,一切正常。

然后我切换到https。现在我在浏览器中看到这个错误:

WebSocket connection to 'wss://example.com/chatHub?id=mKk-uj0P0_7WsLFXjXhskA' failed: Error during WebSocket handshake: Unexpected response code: 200

POST https://example.com/chatHub?id=HSwLlWtJGpBP0Dib6sHobQ 404 (Not Found) 

奇怪的是,即使我看到这个错误,Edge 聊天也能正常工作(在 chrome 和 firefox 上没有)。

这里发生了什么,我该如何解决?客户端是 angular 6 (@aspnet/signalr 用于集线器连接) 后端是 dotnet

编辑:我忘了提,我有后端和客户端使用 nginx 代理。

标签: websocketsignalrangular6signalr-hub

解决方案


原来是nginx的问题。

proxy_set_header  Upgrade $http_upgrade;
proxy_set_header  Connection "Upgrade";

在服务器 nginx.conf 上修复了问题


推荐阅读