混合内容:https 上的页面是通过 https 加载的,但请求的是不安全的

Mixed content: page at https was loaded over https but requested an insecure

我正在使用 Nginx + flask-socketio + aws elb,当 URL 在 https 上加载时,我收到以下与 Nginx 和套接字相关的错误消息,请帮助这个,

socket.io.min.js:2 Mixed Content: The page at 'https://localhost/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://localhost/socket.io/1/?t=1477375737508'. This request has been blocked; the content must be served over HTTPS.d.handshake @ socket.io.min.js:2
socket.io.min.js:2 XMLHttpRequest cannot load http://localhost/socket.io/1/?t=1477375737508. Failed to start loading.

查看您的 .js 文件,确保您使用的是正确的 ajax URL(//your_site.com/handler,而不是 http://your_site.com/handler) ,例如:

$.ajax({
url:'//your_site.com/handler',dataType:'json',type:'get',
success: function(data){...},
complete:function(xhr, textStatus){...}
});

混合内容是当前浏览器采用的一种安全策略,其目标是防止通过 "secure" HTTPS 获取的信息泄漏到非安全上下文中。因此,使用 HTTPS 服务的站点必须使用 HTTPS 或其他支持 TLS 的协议来获取内容。

基于 TLS 的 Websockets 的 URI 前缀是 wss,而普通 Websockets 的 URI 前缀是 ws。至少 Chromium and Firefox 考虑 https+ws 混合内容,并拒绝这样的设置 - 因此 wss 应该用作 secure/HTTPS 上下文中的 URI 前缀而不是 ws.