Before I start, I would like to tell you that this method has been tested on the following settings
- Hosting -> linode.com
- Operating system -> Ubuntu 20.04 LTS Disk
- Domain service provider -> godaddy.com
- Node app -> inside a docker container with port 5000:5000
- Mysql database -> inside a docker container with port 3306:3306
- nginx -> inside root not in docker container it's work like apache server
- certbot -> inside root not in docker container with python3
- You need your setup 1 to 5 ready and running.
- Install NGINX and configure
- Go to root by
cd /
- Now run
sudo apt install nginx
- And run
sudo nano /etc/nginx/sites-available/default
to edit the file - Search for
server_name
and add you domain like:server_name yourdomain.com www.yourdomain.com;
- Add the following to the location part
location / {
proxy_pass http://localhost:5000; #whatever port your app runs on
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
- Save the file and exit
CTRL + O → Enter
CTRL + X
- Check NGINX config
sudo nginx -t
- Restart NGINX
sudo service nginx restart
You should now be able to visit your IP with no port (port 80) and see your app. Now let's Add SSL with LetsEncrypt or certbot
1- Run the following
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
2- Now some users will face problem with this next command- Run
sudo apt-get install python-certbot-nginx
if it's showing you error - Run
sudo apt-get install python3-certbot-nginx
3- And now the final step - Run
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
where -d is your yourdomain if you have no sub-domain remove the second part.
If you have done everything as we mentioned, then you can enter the site and you will see it encrypted with https
Now visit https://yourdomain.com and you should see your Node app
# Only valid for 90 days, test the renewal process with
certbot renew --dry-run