Created
December 18, 2013 20:21
-
-
Save thomseddon/8029276 to your computer and use it in GitHub Desktop.
SSL walkthrough for nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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