我已经在端口80(http)和443(https)上设置了一个express服务器。与服务器分离,我在一个单独的端口中设置了一个WebSocket服务器,node.js

var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 8000});

快递服务的站点必须连接到这些服务才能工作。问题是:通过8000访问我的站点很好,但是,从http中,我得到:
index.js:100 Mixed Content: The page at 'https://example.com/' was
loaded over HTTPS,  but attempted to connect to the insecure
WebSocket endpoint 'ws://my_sites_ip:8000/'. This request has been
blocked; this endpoint must be available over WSS.

为什么我会犯这个错误?这与websocket服务器与http服务器位于不同的进程/端口有关吗?我怎样才能让它工作?

最佳答案

错误在于告诉你该怎么做。使用https时将websocket与wss一起使用
看看这个帖子
html5 Websocket with SSL
websocket连接以http或https握手开始其生命。通过http访问页面时,可以使用ws或wss(websocket secure:ws over tls)。但是,当您的页面通过https加载时,您只能使用wss-浏览器不允许“降级”安全性。

07-27 18:48