Skip to content

Instantly share code, notes, and snippets.

@lancevo
Created June 2, 2021 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lancevo/03ea808566757d8efac8f6fe7c3ecd0f to your computer and use it in GitHub Desktop.
Save lancevo/03ea808566757d8efac8f6fe7c3ecd0f to your computer and use it in GitHub Desktop.
Set up letsencrypt with nginx and node

Set up Let's Encrypt with Nginx and Node

This guide to install SSL cert on Nginx as a reverse proxy, and forward the request to a node app

Install certbot

https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/

$ apt-get update
$ sudo apt-get install certbot
$ apt-get install python-certbot-nginx

Add the domain to Nginx conf

$ sudo vim /etc/nginx/sites-enabled/default

Inside of default conf file add the following to redirect the domain to the localhost port 4444

server {
    listen 80;
    server_name myserver.com;
    
    location / {                                                   
        proxy_pass http://127.0.0.1:4444;                      
        proxy_http_version 1.1;                                        
        proxy_set_header Upgrade $http_upgrade;                        
        proxy_set_header Connection 'upgrade';                         
        proxy_set_header Host $host;                                   
        proxy_set_header X-Forwarded-Proto https;                      
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
   }                                                              
}

Install http-server to serve the static folder ~/www for verification by Let's encrypt

$ npm i -g http-server
$ http-server -p 4444 ./www

Request the SSL cert and configure Nginx at the same time

$ sudo certbot --nginx -w ./www -d myserver.com

the -w param tells certbot where the static folder is to add a file to response to its verification

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