An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

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

问题:

使用nginx配置ssl证书,部署项目时候发现经过ws协议不行了,必须改成wss协议。Websocket使用 ws 或 wss,相似于 HTTP 或 HTTPS ,其中 wss 表示在 TLS 之上的 Websocket ,至关于 HTTPS 了。默认状况下,Websocket 的 ws 协议使用 80 端口。运行在TLS之上时,wss 协议默认使用 443 端口。html

解决方法

参考官方文档: http://nginx.org/en/docs/http/websocket.html前端

在nginx中添加如下配置:nginx

location /websocket {
	proxy_pass http://myblog.lwenhao.com:8080/myblog/websocket;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";
}

须要代理转发到你真正的websocket地址。我是在阿里上申请的域名免费的ssl证书,前端只能经过申请证书的域名去请求,不能经过一级、二级域名请求。web

注意:

默认状况下,若是代理服务器在60秒内未传输任何数据,则将关闭链接。使用proxy_read_timeout指令能够增长此超时。或者,代理服务器能够配置为按期发送WebSocket ping帧以重置超时并检查链接是否仍然存在。服务器

相关文章
相关标签/搜索