Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixed Content error when accessing WebSocket server hosted in a different port

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});

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.

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?

like image 753
MaiaVictor Avatar asked Jun 08 '16 20:06

MaiaVictor


People also ask

How do I fix WebSocket connection error?

Solution 1Check that all the Bot Insight services are running. Check that your firewall settings are configured to accept incoming websocket data. Try to use a different web browser. Restart the Bot Insight Visualization and Bot Insight Scheduler services.

What port does WebSocket run on?

WebSocket connections generally work even if a proxy or firewall is in place. This is because they use ports 80 and 443 which are also used by HTTP connections. In some situations WebSocket connections are blocked over port 80. In this case a secure SSL connection using WSS over port 443 should successfully connect.

Does each WebSocket use a port?

The WebSocket protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. By default the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over TLS [RFC2818].

Can HTTP and WebSocket use same port?

Protocol handshake The handshake starts with an HTTP request/response, allowing servers to handle HTTP connections as well as WebSocket connections on the same port.


1 Answers

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

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.

like image 198
pedrofb Avatar answered Oct 13 '22 14:10

pedrofb