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?
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.
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.
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].
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With