nginx 设置代理需要进行额外的配置
修改nginx 目录下 conf/nginx.conf 文件
配置好nginx
location /ws {
proxy_pass http://localhost:8002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
然后在前端发起请求
this.socketInstance = new WebSocket('ws://' + location.host + process.env.VUE_APP_BASE_SOCKET_PATH)
这样子就可以连通了
提示: 配置文件很重要, 要仔细核对, 特别是从网上拷贝过去的. 这个错了不好发现