Skip to main content

Setting up Node.js servers for private messaging with WebSockets

Use the same SSL certificates for the webservers. Privkey is obtained from the .domain.key file; fullchain is obtained from the .domain.crt file (not the issuer file). 

Switch to root user, and convert them to PEM format using the following:

sudo su
mkdir /opt/bitnami/letsencrypt/node-server-certs/
openssl x509 -in /opt/bitnami/letsencrypt/certificates/_.desertedchateau.com.crt -out /opt/bitnami/letsencrypt/node-server-certs/fullchain.pem -outform PEM
openssl ec -in /opt/bitnami/letsencrypt/certificates/_.desertedchateau.com.key -out /opt/bitnami/letsencrypt/node-server-certs/privkey.pem -outform PEM
cp /opt/bitnami/letsencrypt/certificates/_.desertedchateau.com.json /opt/bitnami/letsencrypt/node-server-certs/_.desertedchateau.com.json

If needed, change ownership and permissions:

chown -R root:root /opt/bitnami/letsencrypt/node-server-certs/
chmod -R 755 /opt/bitnami/letsencrypt/node-server-certs/

Add the IP address of the Node server to the VPC security group, allowing port 6379 for Redis access

Install nodemon (requires root privileges, since the -g flag is installing globally). Log out from root afterwards.

npm install -g nodemon
exit

Restart Apache to ensure it is using the correct certificates:

sudo /opt/bitnami/ctlscript.sh restart apache

Start the node server:

cd /opt/bitnami/apache/htdocs/
nohup nodemon -I public/index.js > nohup.out 2>&1 &