websocket本地調試運行正常,部署服務器報302錯誤

前後端分離項目,本地調試運行一切正常。部署到服務器後,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");

這裏的路徑是自定義的,根據自己項目情況修改。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章