访问不同端口托管的WebSocket服务器时出现混合内容错误 [英] Mixed Content error when accessing WebSocket server hosted in a different port

查看:62
本文介绍了访问不同端口托管的WebSocket服务器时出现混合内容错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've set up an express server with node.js on port 80 (http) and 443 (https). Separate from that server, I've set up a websocket server in a separate port, 8000:

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

express服务的网站必须连接到这些服务才能正常工作。问题是:通过 http 访问我的网站可以正常工作,但是从 https 可以访问:

The site served by express must connect to those services to work. The issue is: accessing my site through http works fine, but, from https, I get:

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服务器位于不同的进程/端口中有关吗?我该如何使用它?

Why I'm getting this error? Has this anything to do with the fact the websocket server is in a different process/port than the http server? How can I get it to work?

推荐答案

该错误告诉您该怎么做。在使用https时将websocket与wss一起使用

The error is telling you what to do. Use websocket with wss when using https

查看此帖子
html5带SSL的Websocket
WebSocket连接通过HTTP或HTTPS握手开始其寿命。通过HTTP访问页面时,可以使用WS或WSS(WebSocket安全:WS over TLS)。但是,通过HTTPS加载页面时,您只能使用WSS-浏览器不允许降级安全性。

Look at this post html5 Websocket with SSL The WebSocket connection starts its life with an HTTP or HTTPS handshake. When the page is accessed through HTTP, you can use WS or WSS (WebSocket secure: WS over TLS) . However, when your page is loaded through HTTPS, you can only use WSS - browsers don't allow to "downgrade" security.

这篇关于访问不同端口托管的WebSocket服务器时出现混合内容错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆