Setup new subdomain on NginX with redirected SSL

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
  1. Run sudo vi /etc/nginx/conf.d/ and copy past below

    server {	if ($host = {		return 301 https://$host$request_uri;	}	listen 80;	listen [::]:80;	server_name;	return 301 https://$host$request_uri;}server {	ssl_certificate /etc/letsencrypt/live/;	ssl_certificate_key /etc/letsencrypt/live/;	listen 443 ssl;	listen [::]:443 ssl;	server_name;	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