bug记录

Error during WebSocket handshake

2020-12-17  本文已影响0人  修行者12138

使用websocket时,前端报错如下
Error during WebSocket handshake: Unexpected response code: 404

经排查,原因是需要在nginx做ws相关配置

正常情况下ng配置

    server {
        listen 8083;
        server_name adms-local.cmft.com;
        access_log  logs/item_access.log main;

        location / {
            proxy_pass http://127.0.0.1:8080;
        }
  
    }

在chrome控制台new WebSocket('ws://adms-local.cmft.com:8083/adms/websocket/1'),报错如下
WebSocket connection to 'ws://adms-local.cmft.com:8083/adms/websocket/1' failed: Error during WebSocket handshake: Unexpected response code: 404

image.png

修改ng配置如下

    server {
        listen 8083;
        server_name adms-local.cmft.com;
        access_log  logs/item_access.log main;

        location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }
  
    }

再次new WebSocket('ws://adms-local.cmft.com:8083/adms/websocket/1'),建立连接成功

image.png
上一篇 下一篇

猜你喜欢

热点阅读