I’ve been trying to set up SSL on NodeJS, serving index.html
through an Apache2 server using CertBot certificates.
Unfortunetly, when I try to make the client to connect to the Server via https, It throws the following error
[index.js:83 GET https://pxlloewe.de:3000/socket.io/?EIO=3&transport=polling&t=NJ9t2YZ net::ERR_SSL_PROTOCOL_ERROR][1]
So, is it possible to still provide the files via appache2 and ssl and connect to the Server with the page loaded https:youDomain.com
?
I tried to get https running on the NodeJS Server but I am don’t want to provide the browser files via Express
Here is my code, if someone got the chance to read sth out of it:
Serverside:
var express = require("express");
var socket = require("socket.io");
var app = express();
const port = 3000
var server = app.listen(port, () => {
console.log("Express App auf Port: ", port)
});
//Socket Setup
var io = socket(server);
io.on("connection", function(){
console.log("Verbunden auf websocket")
})
Clientside:
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js" integrity="sha512-v8ng/uGxkge3d1IJuEo6dJP8JViyvms0cly9pnbfRxT6/31c3dRWxIiwGnMSWwZjHKOuY3EVmijs7k1jz/9bLA==" crossorigin="anonymous"></script>
<title>Einfache Chat App</title>
<script src="chat.js"></script>
</html>
JS:
// Make Connection
var socket = io.connect('pxlloewe.de:3000', {secure: true});
2
Answers
Here are the steps I follow to get things working:
added a subdomain to my main domain (websocket.pxllloewe.de)
routing to my dyndns (got my Server running at home on a raspberryPi)
setting up apache2/LetsEncrypt via Certbot and Proxy. MyConfig:
ServerName websocket.pxlloewe.de ServerAdmin [email protected] DocumentRoot /var/www/html/pxlloewe_de ProxyPreserveHost On ProxyRequests Off ProxyPass /socket.io http://localhost:3000/socket.io ProxyPassReverse /socket.io http://localhost:3000/socket.ioThanks for your help Aviv Lo! Working out fine now.
I am grabbing this apache site conf. straight from my site in production. It is then modified to suite your need.