How to get HTTPS working on your local Rails server on Ubuntu

After reading a bunch of tutorials on the subject and trying out a variety of suggestions, here’s the shortest path I found to localhost HTTPS bliss on Ubuntu for Rails:

  1. Follow this excellent guide. It will instruct you how to create local root certificate and generate domain certificate for the localhost domain. But it’s written for mac users in mind, so when it mentions Keychain, it’s time to move to paragraph 2. It also uses node.js server as an example. For Rails, you’ll need paragraph 3.
  2. You need to get your Chrome and Firefox to recognize your new local root certificate. To make this work on Ubuntu, follow this guide. When running the helper script, you may get an error:  certutil: could not authenticate to token NSS Certificate DB.: SEC_ERROR_IO: An I/O error occurred during security authorization.  Don’t worry about this.
  3. Some tutorials tell you need to add   in your Rails development environment. But the following should work without touching your Rails config files, .hosts file or any other OS or web server configuration:
    • Move the server.crt and server.key files you created in the end of the tutorial in paragraph 1 to your Rails app directory and rename them localhost.crt and localhost.key (just because they would be easier to identify this way).
    • Add Thin to your Gemfile (if you don’t have it already):
    • Run thin server: thin start --ssl --ssl-key-file localhost.key --ssl-cert-file localhost.crt
    • Go to https://localhost:3000
    • Great success!

Leave a Reply

Your email address will not be published. Required fields are marked *