Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 访问托管在不同端口中的WebSocket服务器时出现混合内容错误_Node.js_Ssl_Https_Websocket_Certificate - Fatal编程技术网

Node.js 访问托管在不同端口中的WebSocket服务器时出现混合内容错误

Node.js 访问托管在不同端口中的WebSocket服务器时出现混合内容错误,node.js,ssl,https,websocket,certificate,Node.js,Ssl,Https,Websocket,Certificate,我已经在端口80(http)和443(https)上用node.js设置了一个express服务器。与该服务器分开,我在一个单独的端口中设置了一个websocket服务器,8000: var WebSocketServer = require('ws').Server; var wss = new WebSocketServer({port: 8000}); express服务的站点必须连接到这些服务才能工作。问题是:通过http访问我的站点很好,但是,通过https,我得到: index.j

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

var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 8000});
express服务的站点必须连接到这些服务才能工作。问题是:通过
http
访问我的站点很好,但是,通过
https
,我得到:

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一起使用

看看这个帖子
WebSocket连接从HTTP或HTTPS握手开始。当通过HTTP访问页面时,可以使用WS或WSS(WebSocket安全:WS over TLS)。但是,当您的页面通过HTTPS加载时,您只能使用WSS-浏览器不允许“降级”安全性。

Hi我必须使用WSS的地方?您必须切换URL方案和端口。例如:wss://test.mosquitto.org:8081 对于那些试图从docker容器中运行Vue Vite HMR模块的人来说,这将是非常有见地的,而不是:ws://test.mosquitto.org:8080。