0

Our website has been running on an internal test machine where it could be accessed by all computers inside the network.

Now we want to deploy this website on a webserver (Apache2) to make it available to our clients. We want to use https and this is where we encountered a problem.

The Socket.io client can´t connect to the node.js server since switching to https. We are using a signed certificate from a trusted CA. I have tried every solution I could find but none seem to work for our case.

Constructor used with ngx-socket-io in angular:

constructor() {
    super({url: 'https://mywebPage.com:8080',options:{secure: true,  origin: '*', transport:['websocket']}})
}

Our certificate seems to be valid since it works for our angular page. We are also able to make HTTPS GET/POST requests to our API which is located on the same server.

node.js socket.io server code:

var options = {
    key: fs.readFileSync('/etc/apache2/folder/certificate.com.key'),
    cert: fs.readFileSync('/etc/apache2/folder/certificate.com.public.crt'),
    ca: fs.readFileSync('/etc/apache2/folder/certificate-intermediate.crt'),
    requestCert: true
};
let server = require('https').createServer(options);  
let io = require('socket.io')(server);

server.listen(8080);
console.log("Server started on Port 8080");

the client tries to connect to the socket-Server but fails and gets the net::ERR_CONNECTION_CLOSED the rest of the web page loads fine and has a valid certificate

We have also tested to see if the port on the web server is accesible and it seems to be open in netstat and nma.

If any more information is needed I am glad to provide.

EDIT: have tested the setup with rejectUnauthorized:false on the client side but that does not change the error. similar stack overflow questions which i have considered in solving the problem:

socket.io net::ERR_CONNECTION_CLOSED

Setup Server-Server SSL communication using socket.io in node.js

Bjamer
  • 1
  • 3
  • Should i remove my question now that i have found the answer? If anybody knows how to handle this please let me know – Bjamer Mar 10 '20 at 14:35
  • I would suggest writing your solution from the updated question in a separate answer and mark it solved, and keep the question so others can learn from it – hreimer Sep 04 '20 at 03:36

1 Answers1

0

added requestCert: false, rejectUnauthorized: false into my node.js options. Now the previous Error has been resolved.

New error persists but seems to be of a different nature:

error during WebSocket handshake: Unexpected response code: 400
Bjamer
  • 1
  • 3