Skip to content

Instantly share code, notes, and snippets.

@jbenesch
Created April 14, 2016 17:38
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 jbenesch/cc7100dd0da7ce49bf4d2e08ab2367cc to your computer and use it in GitHub Desktop.
Save jbenesch/cc7100dd0da7ce49bf4d2e08ab2367cc to your computer and use it in GitHub Desktop.
Self signed SSL certificates and NGINX conf creation.
#!/bin/sh
[ -z "$1" ] && echo "Usage: ssl <hostname>" && exit 1
# Create the certs
rm -rf /mnt/certs/$1
mkdir /mnt/certs/$1
cd /mnt/certs/$1
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
# Write the vhost file to /mnt/vhosts/$1.conf
cat > "/mnt/vhosts/$1.conf" <<END
server {
listen 80;
server_name $1 www.$1;
access_log off;
return 301 https://\$server_name\$request_uri;
}
server {
listen 443 ssl;
server_name $1 www.$1;
access_log off;
# add Strict-Transport-Security to prevent man in the middle attacks
add_header Strict-Transport-Security "max-age=31536000";
# proxy_set_header X-Forwarded-Proto 'https';
ssl on;
ssl_certificate /mnt/certs/$1/server.crt;
ssl_certificate_key /mnt/certs/$1/server.key;
include /mnt/nginx/security.conf;
location / {
proxy_pass http://webservers;
}
}
END
# Set up Wordpress
wp plugin activate wordpress-https --url=$1 --path=/path/to/wp/install --allow-root
wp search-replace 'http://' 'https://' --url=$1 --path=/path/to/wp/install --allow-root
echo "All Done."
echo "Make sure you add this to your wp-config.php file: define( 'FORCE_SSL_ADMIN', true );"
echo "You'll also need to reload your nginx configuration files: service nginx reload"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment