https域名连接websocket

问题:

        之前项目访问域名是http的,使用80端口,由于安全原因,改成https的域名。改成https后,前端websockt连接出现了了问题,报错:

1 Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://xxx'. This request has been blocked; this endpoint must be available over WSS.

解决:

        看提示,是ws和wss的问题,讲前端websocket连接改成wss即可,同时需要修改nginx配置:


location /webSocket {
   proxy_pass  http://host;
   proxy_set_header Host $host;
   proxy_set_header Upgrade 'websocket';
   proxy_set_header Connection 'Upgrade';
}

最后贴一个在线测试websocket的网站,感觉不错:在线测试websocket

你可能感兴趣的:(WebSocket)