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.
- run certbot
sudo certbot --nginx -d subdomain.dipsy.me
-
Run
sudo vi /etc/nginx/conf.d/subdomain.dipsy.me
and copy past belowserver { 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"; }}
-
test whether you have typed correctly
sudo nginx -t
-
restart nginx
sudo systemctl reload nginx