前后端分离项目,本地调试运行一切正常。部署到服务器后,websocket连接报错。
报错: Error during WebSocket handshake: Unexpected response code: 302
错误原因:
1、nginx中缺少支持websocket配置
在后台server location中加入三行:
location {
# WebScoket Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
2、后台权限控制shiro加入
filterChainDefinitionMap.put("/websocket/**", "anon");
这里的路径是自定义的,根据自己项目情况修改。