samiles
170
8
Forge

Setting on Node.js Socket.io on Laravel Forge

Posted 3 years ago by samiles

Hi,

I have had a Socket.io server running just fine with my Forge site over HTTP. Since upgrading to HTTPS the connection has broken. I need to set up Socket.io running on my server with SSL. I have multiple sites installed on the server.

I was originally connecting to http://socket.mydomain.com but simply switching to https://socket.mydomain.com and installing SSL on the sub domain doesn't work. It gives a Nginx Bad Gateway error.

Does anyone know how to set this up? My front end code to connect is:

<script type="text/javascript" src="https://socket.example.com/socket.io/socket.io.js"></script>
<script>
var io = io('https://socket.example.com', { secure: true });
</script>

The code of my Socket.io script is:

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

var options = {
    key:    fs.readFileSync('/etc/nginx/ssl/default/54082/server.key'),
    cert:   fs.readFileSync('/etc/nginx/ssl/default/54082/server.crt')
};
var app = https.createServer(options);

var io = require('socket.io').listen(app);

app.listen(3000);

I know the Node.js code is running as it is receiving events and is showing the output it is receiving from Laravel in the terminal - just cannot connect on the front end.

Any ideas on how to achieve this set up and fix the SSL issue? What should the addresses be? I've found no tutorials on setting up with SSL. Thanks

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.