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

IAm*_*mes 5 nginx flask flask-sockets flask-socketio

我正在使用 Nginx + Flask-socketio + aws elb,当在 https 上加载 URL 时,我收到以下错误消息,该消息与 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.
Run Code Online (Sandbox Code Playgroud)

小智 4

查看您的.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){...}
});
Run Code Online (Sandbox Code Playgroud)

  • 事实上,我在我的 js 文件中忽略了这一点,而我一直在胡言乱语。现在我收到“WebSocket 连接到'ws://example.com/socket.io/1/websocket/654646646'失败:WebSocket 握手期间出错:意外的响应代码:500” (2认同)