How can I setup a local SSL certificate and a Rails application?

ftshtw picture ftshtw · Jan 25, 2016 · Viewed 8.6k times · Source

This might be a two-in-one question.

  1. I have a Rails application for home/hobby usage, hosted on a Raspberry Pi and I was wondering if it's possible to create a local SSL certificate for it and setup Rails to use it?

  2. If yes, how can I setup my Rails/Puma/Foreman/Ubuntu application? For now, I am running the application with Foreman, by using a Procfile:

    web: bundle exec puma -t 8:8 -p 3000
    worker: bundle exec sidekiq
    clock: bundle exec clockwork config/clock.rb
    

Answer

Chris Valentine picture Chris Valentine · Apr 23, 2016
  1. Yes you can. Here is a gist explaining the process:

https://gist.github.com/tadast/9932075

  1. My procfile contains an entry that looks like this:

    server: rails server puma -b 'ssl://0.0.0.0:3000?key=server.key&cert=server.crt'

This seems to work for me. I also set

config.force_ssl = true 

in config/application.rb

I gathered info about it from all these places:

https://github.com/puma/puma

http://www.railway.at/2013/02/12/using-ssl-in-your-local-rails-environment/

http://www.panozzaj.com/blog/2013/08/12/how-to-set-up-local-https-development/

http://www.eq8.eu/blogs/14-config-force_ssl-is-different-than-controller-force_ssl