Websocket Reverse Proxy over TLS

TafD

New Member
#1
I have followed the post of reverse proxying Websockets using OpenLightSpeed. What I have not found is how to do it over tls ( wss ). My application needs to access the websockets server over a secure channel and how can I achieve that in OpenLightSpeed?
 

Cold-Egg

Administrator
#2
LiteSpeed currently can only offload SSL and forward to the backend using ws://. wss:// is not currently supported, and there are no plans to make it available soon. If you must, you could try an SSL tunnel. LiteSpeed communicates with the SSL tunnel via ws://, the SSL tunnel adds SSL encryption, and then the tunnel communicates with the backend via wss://.
 
#4
@Cold-Egg I install Mattermost with docker in cyberpanel, I set a reverse proxy and its fine, works in https://tutor.frikidog.com without problem, but websocket is wss:// and as you said in openlitespeed only works ws://, and I think thats the reason why show me "Please check connection, Mattermost unreachable. If issue persists, ask administrator to check WebSocket port. " and I understand that, openlitespeed don´t work with wss://. But I am newbie, and I don´t know how to make a SSL Tunnel, I search in goolgle and i find "stunnel" but after several attempts I have not achieved anything. Can you help me with a tutorial or say me the correct way to do this please? thanks! or how did you manage to do an SSL tunnel @TafD ? any help I will appreciate-
 
#5
Hi @Cold-Egg I installed N8N and reverse proxying through OLS, and in the browser console I can see failure to communicate to wss://DOMAIN.
My TLS is being handled by OLS so I guess no option to make it working or would that SSL tunnel option work? could you please elaborate a bit on how to configure it?
 

Cold-Egg

Administrator
#6
Hi @DonSYS91

Setup Example socket and start it.
This is what I have tried, setup an example site by following some online posts
server.js
Code:
const WebSocket = require('ws');

const server = new WebSocket.Server({ port: 8080 });

server.on('connection', (socket) => {
  console.log('Client connected');

  socket.on('message', (message) => {
    console.log(`Received: ${message}`);
    socket.send(message); // Echo back the message
  });

  socket.on('close', () => {
    console.log('Client disconnected');
  });
});

console.log('WebSocket server is running on ws://localhost:8080');
Start the service with "node server.js" command
WebSocket server is running on ws://localhost:8080

Setup OLS with SSL enabled

Then Apply SSL certificate and add the cert to OLS listener or SSL at virtual host level. Follow https://docs.openlitespeed.org/config/#set-up-listeners

Then follow https://docs.openlitespeed.org/config/reverseproxy/websocket/ to setup the websocket proxy
URI: /
Address: localhost:8080
1733365796646.png
Test it
Then test it with https://livepersoninc.github.io/ws-test-page/ and https://ws-playground.netlify.app/ online tools.

URL: wss://xxx.com
Connection Status: Connected
Send "test wss" message

1733365763125.png

Node received:
Client connected
Received: test wss

Could you verify if my above test steps are valid?
 

Attachments

#7
Hi @Cold-Egg , as always OLS without your amazing help is nothing! Thank you so much!
I ended up doing exactly same tests as you did and even dockerized it to approach same settings as my N8N with identical vhost conf as my N8N.
WSS is always working.

N8N still didn't want to work and that won't make any sense.
To my amazement I don't know yet what the reason might be but Websocket worked on Firefox and Chrome not!

I think it's something that N8N team needs to figure out. For now anyone that uses N8N behind OLS it's working perfectly but not in combination with Chrome.

Thanks again Cold Egg!
 
Top