Skip to content

Instantly share code, notes, and snippets.

@dbtlr
Created February 6, 2017 02:35
Show Gist options
  • Save dbtlr/3b791116d7897f0141d233bfcd042a56 to your computer and use it in GitHub Desktop.
Save dbtlr/3b791116d7897f0141d233bfcd042a56 to your computer and use it in GitHub Desktop.
Add a redirect for a domain name, over to a new url in Nginx w/ LetsEncrypt ssl cert
#!/bin/bash
FROM_DOMAIN=$1
TO_URL=$2
echo "
server {
listen 80;
server_name $FROM_DOMAIN;
return 301 $TO_URL;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name $FROM_DOMAIN;
ssl_certificate /etc/letsencrypt/live/$FROM_DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$FROM_DOMAIN/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
return 301 $TO_URL;
}
" > ~/$FROM_DOMAIN.conf
sudo mv ~/$FROM_DOMAIN.conf /etc/nginx/sites-available/$FROM_DOMAIN
sudo rm /etc/nginx/sites-enabled/$FROM_DOMAIN
sudo ln -s /etc/nginx/sites-available/$FROM_DOMAIN /etc/nginx/sites-enabled/$FROM_DOMAIN
sudo service nginx stop
sudo certbot certonly --standalone -d $FROM_DOMAIN
sudo service nginx start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment