Skip to content

Instantly share code, notes, and snippets.

@floptwo
Last active November 27, 2020 21:04
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 floptwo/e3bd7eb049e00181443af75f96ef50b0 to your computer and use it in GitHub Desktop.
Save floptwo/e3bd7eb049e00181443af75f96ef50b0 to your computer and use it in GitHub Desktop.
How to add SSL to your local development environment using Ruby on Rails with Puma

How to add SSL to your local development environment using Ruby on Rails with Puma

Sources:

brew install mkcert
brew install nss
mkcert -install
mkcert mywebsite.test "*.mywebsite.test"

Add the code below to your config/puma.rb

if ENV["RAILS_ENV"] == "development"
  clear_binds! # Remove the tcp:// binds that stops ssl:// to work
  ssl_bind "0.0.0.0", 3000, {
    key: File.join("config", "local-certs", "mywebsite-key.pem"),
    cert: File.join("config", "local-certs", "mywebsite.pem"),
    verify_mode: "none"
  }
end

So, to start your server you can do

rails s

instead of

rails s puma -b 'ssl://0.0.0.0:3001?cert=config/local-certs/mywebsite.pem&key=config/local-certs/mywebsite-key.pem&verify_mode=none&no_tlsv1=false&no_tlsv1_1=false'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment