Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SSL on localhost, reusuable across multiple Rails apps
# SSL self signed localhost for rails start to finish, no red warnings.
# 0) Unless present, create `~/.ssl/`
$ mkdir ~/.ssl
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out ~/.ssl/localhost.orig.key 2048
# 2) Remove the password
$ openssl rsa -in ~/.ssl/localhost.orig.key -out ~/.ssl/localhost.key
# 3) Generate the csr (Certificate signing request) (Details are important!)
$ openssl req -new -key ~/.ssl/localhost.key -out ~/.ssl/localhost.csr
# MUST have localhost.ssl as the common name to keep browsers happy
# (has to do with non internal domain names ... which sadly can be
# avoided with a domain name with a "." in the middle of it somewhere)
Country Name (2 letter code) [AU]:
Common Name: localhost.ssl
# 4) Generate self signed ssl certificate
$ openssl x509 -req -days 365 -in ~/.ssl/localhost.csr -signkey ~/.ssl/localhost.key -out ~/.ssl/localhost.crt
# 5) Finally Add localhost.ssl to your hosts file
$ echo " localhost.ssl" | sudo tee -a /etc/hosts
# 6) Boot thin
# thin < 1.6.2
$ bundle exec thin start --ssl --ssl-verify --ssl-key-file ~/.ssl/localhost.key --ssl-cert-file ~/.ssl/localhost.crt
# thin >= 1.6.2
$ bundle exec thin start --ssl --ssl-key-file ~/.ssl/localhost.key --ssl-cert-file ~/.ssl/localhost.crt
# 7) Add localhost.crt as trusted !!SYSTEM!! (not login) cert in the mac osx keychain
# Open keychain tool, drag .crt file to system, and trust everything.
# Notes:
# 1) Https traffic and http traffic can't be served from the same thin process. If you want
# both you need to start two instances on different ports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment