本地连接websocket都可以连接成功,但是发布到线上就一直报错连接失败,先从服务器安全组检查起,看安全组是否添加websocket默认端口443,然后检查服务器防火墙是否添加443端口
使用 sudo iptables -L -n命令查看防火墙配置
查看防火墙有443配置后
使用sudo netstat -tuln | grep 443 查看是否含有443
如果以上都有了,那么再看nginx部署你关于wss,websocket的接口转发里面有没有添加请求头
#http升级会websocket需要添加的请求头
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
重启nginx
sudo systemctl reload nginx
至此问题全部解决