Skip to content

Instantly share code, notes, and snippets.

@mfts
Created June 3, 2020 08:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfts/0b4f8d2ec5fb7adba172c33d5eebc111 to your computer and use it in GitHub Desktop.
Save mfts/0b4f8d2ec5fb7adba172c33d5eebc111 to your computer and use it in GitHub Desktop.
Let's Encrypt for Wildcard Domains with Heroku and Cloudflare
#!/bin/sh
set -e
# NEEDS THE FOLLOWING VARS IN ENV:
# DOMAIN
# CLOUDFLARE_EMAIL
# CLOUDFLARE_API_KEY
# HEROKU_APP
# Download dependencies
git clone https://github.com/Neilpang/acme.sh.git
cd ./acme.sh
# Force ensures it doesnt fail because of lack of cron
./acme.sh --install --force
# Map to environment variables that the ACME script requires
export CF_Email=$CLOUDFLARE_EMAIL
export CF_Key=$CLOUDFLARE_API_KEY
# Generate wildcard certificate (this will take approx 130s)
~/.acme.sh/acme.sh --issue -d $DOMAIN -d "*.$DOMAIN" --dns dns_cf
# Update the certificate in the live app
heroku certs:update "~/.acme.sh/$DOMAIN/fullchain.cer" "~/.acme.sh/$DOMAIN/$DOMAIN.key" --confirm $HEROKU_APP --app $HEROKU_APP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment