前後端分離項目,本地調試運行一切正常。部署到服務器後,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");
這裏的路徑是自定義的,根據自己項目情況修改。