由于SignalR将WebSocket作为底层传输方式的优先实现,需要配置Nginx 支持WebSocket(详见SignalR的介绍)
错误解决汇总(Nginx支持WebSocket反向代理)
1 WebSocket connection to 'ws://localhost:8000/chat?id=a_' failed: Error during WebSocket handshake: Unexpected response code: 200。
原因:未配置Nginx 支持WebSocket。
解决:nginx.conf文件location(包含SingalR服务端转发)
添加以下3行
# 启用支持websocket连接
proxy_http_version 1.1; #如果没有这句,会产生409错误
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
2 WebSocket connection to 'ws://localhost:8000/chat?id=QRhslq' failed: Error during WebSocket handshake: Unexpected response code: 409。
原因:未知
解决:nginx.conf文件location(包含SingalR服务端转发)
添加 proxy_http_version 1.1;
3 POST http://localhost:8000/chat/negotiate
502 (Bad Gateway)。
原因: proxy_pass的服务器没有打开(>500错误代码一般是服务器内部错误)。
解决:打开proxy_pass的服务器即可。