pm2 SSL/https connection

574 views
Skip to first unread message

Abhilasha Kumar

unread,
May 23, 2022, 9:35:14 AM5/23/22
to nodeGame
Hi, 

I'm trying to enable a HTTPS connection to my game via pm2. I followed the instructions on this page: https://github.com/nodeGame/nodegame/wiki/HTTPS 

I was able to get the SSL certificate and private key files into the node_modules/ssl folder. This might be a simple question but how do I use pm2 to use the SSL certificate and make that default? 

So far i've been using  pm2 start launcher -- --default mygame which runs over http. What do I change to get it to use https?

Thanks!
Abhilasha

Stefano Balietti

unread,
May 23, 2022, 10:33:38 AM5/23/22
to node...@googlegroups.com
Hi!

Have you tried:

pm2 start launcher -- --ssl --default mygame

Best,
Stefano

--
You received this message because you are subscribed to the Google Groups "nodeGame" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodegame+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodegame/0290557b-7e53-4a5e-a4cc-895ff9a89c9bn%40googlegroups.com.

Abhilasha Kumar

unread,
May 23, 2022, 10:37:18 AM5/23/22
to nodeGame
Hi, I just tried this, and I get an error when I try to connect. Any ideas why this won't work?
Screen Shot 2022-05-23 at 10.35.49 AM.png

Stefano Balietti

unread,
May 23, 2022, 4:48:08 PM5/23/22
to node...@googlegroups.com
Hi,

I am not sure. Please try these steps without pm2 first:

- Create a ssl directory inside the root dir (e.g., nodegame-v-7.x-x/) 
- Copy inside ssl directory two files: private.key and certificate.pem
- Start server with option --ssl ssl (that is the path to the ssl directory)

Open browser to https://address:port

Does it work?

Best,
Stefano



Abhilasha Kumar

unread,
May 24, 2022, 8:43:48 AM5/24/22
to node...@googlegroups.com
Hi, thanks for the input. So my SSL files (the certificate.pem and private.key) are stored inside nodegame-v7.1.0-dev/node_modules/nodegame-server/ssl. 

So, I ran the following: 


node launcher --ssl node_modules/nodegame-server/ssl


after which I get the following output:


Screen Shot 2022-05-24 at 8.38.29 AM.png


I'm assuming this means the game is getting started (I haven't added authorization codes yet but will do). But I am not able to open it in the browser. I tried https://159.65.233.69 by itself, but also tried it with 3 different ports (https://159.65.233.69:80 or https://159.65.233.69:22 or https://159.65.233.69:443) but no luck. Have I not stored the correct SSL files? I used ZeroSSL to install the certificate and was able to verify the SSL so I assumed I did it correctly but maybe not?


Abhilasha




You received this message because you are subscribed to a topic in the Google Groups "nodeGame" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodegame/uMzwGY0oWWo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodegame+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodegame/CAMSNNMmD_nku96uUQm0YVxnadbUp-fAGFdNEKa8v2sDapvei5Q%40mail.gmail.com.

Stefano Balietti

unread,
May 24, 2022, 3:52:01 PM5/24/22
to node...@googlegroups.com
Hi,

If you are using the default nodeGame droplet from the marketplace, then there is Nginx as a reverse proxy server in front of node. So, you need to actually handle ssl via Nginx. Here are the steps:


The command to restart nginx is:

systemctl restart nginx

Let me know if it works for you.

Best,
Stefano

Can Çelebi

unread,
May 25, 2022, 4:09:59 AM5/25/22
to nodeGame
Hello,

I had a similar issue recently. I ended up using certbot to get an ssl for free (even though I bought one). If you are using digital ocean and got the default nodeGame droplet from the marketplace then you can follow these steps to certify your domain from the server console.
https://certbot.eff.org/instructions?ws=nginx&os=ubuntubionic

Note that I have also enabled let's encrypt feature from the digital ocean dashboard (but this did nothing on its own). I am not sure whether having this feature enabled was necessary to the the above steps or not. You can find how to enable let's encrypt from digital ocean in digital ocean's tutorial section.

Best,
Can


Abhilasha Kumar

unread,
May 25, 2022, 9:55:50 AM5/25/22
to node...@googlegroups.com
Hi Stefano,

I see - thanks for the input, I am indeed using the nodeGame droplet from the marketplace. So I tried to change the default file inside root/etc/nginx/sites-enabled and then restart nginx but I get the following error "Job for nginx.service failed because the control process exited with error code.See "systemctl status nginx.service" and "journalctl -xe" for details"

When I try "systemctl status nginx.service" the following output is produced:

Screen Shot 2022-05-25 at 9.51.35 AM.png

Any thoughts?

Thanks,
Abhilasha



Stefano Balietti

unread,
May 25, 2022, 10:54:08 AM5/25/22
to node...@googlegroups.com
That is generally due to an error in the configuration file. It takes a couple of attempts to get it right, but it is generally a semicolon missing at the end of the row. You can check the nginx logs under, I believe, /var/logs/nginx or similar.

Abhilasha Kumar

unread,
May 25, 2022, 11:35:44 AM5/25/22
to node...@googlegroups.com
Voila! Had to fix the path to the SSL certificate - thanks for the tip about checking the logs! It's working now :) 

Abhilasha

Stefano Balietti

unread,
May 25, 2022, 12:41:48 PM5/25/22
to node...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages