Letsencrypt working with socket io


#1

Hi,

I have 2 web applications that use socket io and this 2 web applications are on the same server.
When I doesn’t have the Letsencrypt installed, the sockets worked well in the both applications but I installed Letsencrypt (through rwssl) and now I only can have the sockets worked in only one applicatition.
there is any solution for my problem?


#2

Can you show what the applications are?

Are the two applications the same?

Are you using wss:// in both applications?


#3

Thanks for your reply _az

No, they are different aplications.
Both applications are developed in laravel with angularjs.
In one aplicatition (lets call app.mydomin.com), I use this code on socket.js

var app = require('express')();

var https = require('https'),
fs = require('fs');

var options = { 
	key: fs.readFileSync('/etc/letsencrypt/live/app.mydomian.com/privkey.pem'),
	cert: fs.readFileSync('/etc/letsencrypt/live/app.mydomian.com/cert.pem'),
	ca: fs.readFileSync('/etc/letsencrypt/live/app.mydomian.com/chain.pem')
};


var app = https.createServer(options);
io = require('socket.io').listen(app);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('channel', function (err, count) {
});
redis.on('message', function (channel, message) {
//console.log('Message Recieved: ' + message);
message = JSON.parse(message);
io.emit(channel + ':' + message.event, message.data);
});
app.listen(3000, function () {

});

In the other application (i don’t need ssl installed) I user this code: (lets call alpha.mydomain.com):

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('channel-alpha', function (err, count) {
});
redis.on('message', function (channel, message) {
    //console.log('Message Recieved: ' + message);
    message = JSON.parse(message);
    io.emit(channel + ':' + message.event, message.data);
});
http.listen(3010, function () {
    //console.log('Listening on Port 3010');
});

#4

It’s hard to understand what’s going on without seeing the sites themselves.

The one thing I will suggest is that if you have a website that is accessed via https, e.g.

https://my.app <-- Secure 

Browsers will refuse to make websocket connections from that website to insecure origins:

ws://api.frontend.app <-- Insecure, won't work from a secure website

The websocket service would need to be accessed using HTTPS:

wss://api.frontend.app <-- Secure

That may not be what’s going on, but it’s my guess based on what information you’ve given. If you can, collect errors from your browser’s console and Network Inspector if you can find any.


#5

Oh, forget @_az… i’m so dumb…

I need to open the doors to allow the communications. I already did this but maybe when I install the rwssl it closed the doors. Anyway the problem is resolved.
Thanks for the replies @_az


#6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.