Setup new subdomain on NginX with redirected SSL

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

This util is to generate nginx ssl config with enforced HTTPS for a subdomain, and generate cert with certbot let's encrypt

Please refer to these articles for details: Certbot official / Digital Ocean

First enter the subdomain, then enter the port of the localhost server you want this subdomain to proxy to.

  1. run certbot
sudo certbot --nginx -d subdomain.dipsy.me
  1. Run sudo vi /etc/nginx/conf.d/subdomain.dipsy.me and copy past below

    server {if ($host = subdomain.dipsy.me) {	return 301 https://$host$request_uri;}listen 80;listen [::]:80;server_name subdomain.dipsy.me;return 301 https://$host$request_uri;}server {ssl_certificate /etc/letsencrypt/live/subdomain.dipsy.me/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/subdomain.dipsy.me/privkey.pem;listen 443 ssl;listen [::]:443 ssl;server_name subdomain.dipsy.me;location / {	proxy_set_header Host $http_host;	proxy_set_header X-Real-IP $remote_addr;	proxy_pass http://localhost:3000/;	proxy_http_version 1.1;	proxy_set_header Upgrade $http_upgrade;	proxy_set_header Connection "upgrade";}}
  2. test whether you have typed correctly sudo nginx -t

  3. restart nginx sudo systemctl reload nginx