Skip to content

Instantly share code, notes, and snippets.

@webee
Last active December 12, 2016 06:11
Show Gist options
  • Save webee/8c4d9a5359b88bd23c72a25c5cd2f1b5 to your computer and use it in GitHub Desktop.
Save webee/8c4d9a5359b88bd23c72a25c5cd2f1b5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# /etc/nginx/ssl/<site>/
site=$1
# DNS:www.abc.xyz,DNS:xyz.abc.xyz
domains=$2
OPENSSL_CNF=/etc/pki/tls/openssl.cnf
ssl_dir=/etc/nginx/ssl
mkdir -p ${ssl_dir}
cd ${ssl_dir}
! [ -f account.key ] && openssl genrsa 4096 > account.key
! [ -f domain.key ] && openssl genrsa 4096 > domain.key
mkdir -p ${site}
if ! [ -f "${site}/domain.csr" ]; then
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat ${OPENSSL_CNF} <(printf "[SAN]\nsubjectAltName=${domains}")) > ${site}/domain.csr
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment