Skip to content

Instantly share code, notes, and snippets.

@thomseddon
Created December 18, 2013 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomseddon/8029276 to your computer and use it in GitHub Desktop.
Save thomseddon/8029276 to your computer and use it in GitHub Desktop.
SSL walkthrough for nginx
#!/bin/bash
# Copyright 2013-present Thom Seddon
if [ "$1" == "" ]; then
echo "Usage: sudo ./mkcrt <hostname>"
exit 1
fi
if [ "$(id -u)" != "0" ]; then
echo "Must run with sudo"
exit 1
fi
host=$1
# Setup
if [ ! -d /etc/nginx/ssl ]; then
mkdir /etc/nginx/ssl
fi
cd /etc/nginx/ssl
# Create CSR
openssl genrsa -out $host.key 2048
openssl req -new -key $host.key -out $host.csr
# Sign using 3rd part
echo "You now need to sign your certificate, here is your CSR:"
cat $host.csr
echo
# Chain
echo "Once this is done, you should concat the certificate chain in the \
following order:"
echo "cat [yours] [intemediate] [root] > $host.crt"
echo
# nginx
echo "You can then add the following to your nginx config:"
echo
echo "ssl on;"
echo "ssl_certificate /etc/nginx/ssl/$host.crt;"
echo "ssl_certificate_key /etc/nginx/ssl/$host.key;"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment