Skip to content

Instantly share code, notes, and snippets.

@mfo
Last active December 11, 2015 03:48
Show Gist options
  • Save mfo/4540602 to your computer and use it in GitHub Desktop.
Save mfo/4540602 to your computer and use it in GitHub Desktop.
Example of heroku-forward with SSL support for your development environment

create SSL certificates for thin / heroku-forward

# create an SSL folder for your environment.
mkdir -p ~/.ssl/development/
cd ~/.ssl/development/

# create private key / certificate for your app 
# /!\ remember to define the expected common name for you development hostname [if your using localhost, use localhost. If you are using a custom domain, use it]
openssl genrsa -out my_app_key.pem 1024 
openssl req -new -key my_app_key.pem -out my_app_certrequest.csr 
openssl x509 -req -in my_app_certrequest.csr -signkey my_app_key.pem -out my_app_certificate.pem
chmod 600 ./*

link your key / certificate

SSL env var

# i'm using .rvmrc, you can add it to your $HOME/.bashrc
cd ~/my_app
echo 'export THIN_SSL_ENABLED=true' >> .rvmrc
echo 'export THIN_SSL_CERT_FILE="$HOME/.ssl/development/my_app_certificate.pem"' >> .rvmrc
echo 'export THIN_SSL_KEY_FILE="$HOME/.ssl/development/my_app_key.pem"' >> .rvmrc
source .rvmrc

update config.ru to enable SSL on dev

options = { application: application }
if ENV['THIN_SSL_ENABLED']
  options[:ssl] = true
  options[:ssl_verify] = true
  options[:ssl_cert_file] = ENV['THIN_SSL_CERT_FILE']
  options[:ssl_key_file] = ENV['THIN_SSL_KEY_FILE']
end
backend = Heroku::Forward::Backends::Thin.new(options)

update your development.rb to force ssl

config.force_ssl = true

try it*

foreman start -f my_app_Procfile

voila!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment