Skip to content

Instantly share code, notes, and snippets.

@Nick390
Last active December 26, 2022 21:39
Show Gist options
  • Save Nick390/9a4f553e7209ffc7f483dcc50c091d45 to your computer and use it in GitHub Desktop.
Save Nick390/9a4f553e7209ffc7f483dcc50c091d45 to your computer and use it in GitHub Desktop.
How to set https on linode + godaddy + ubuntu + certbot + docker + nodejs + nginx

How to setup https on your website?

Before I start, I would like to tell you that this method has been tested on the following settings

  1. Hosting -> linode.com
  2. Operating system -> Ubuntu 20.04 LTS Disk
  3. Domain service provider -> godaddy.com
  4. Node app -> inside a docker container with port 5000:5000
  5. Mysql database -> inside a docker container with port 3306:3306
  6. nginx -> inside root not in docker container it's work like apache server
  7. certbot -> inside root not in docker container with python3

How to start?

  1. You need your setup 1 to 5 ready and running.
  2. 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.

Congratulations!

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

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment