Instant Local Nginx SSL/TLS Proxy

Posted on May 20, 2015 by Carsten Zimmermann

Ideally, your Rails app just has config.force_ssl = true configured for its production environment. However, if you have TLS- and non-TLS contexts in your app, things become tricky to test on your local development machine.

For Dev/Prod Parity, I want to have the same SSL setup locally as on staging/production. Documentation for setting up a local Nginx instance is readily available, but it’s verbose and involves too many manual steps.

Automate all the things!

I’ve written a shell script to automate the happy path of the Nginx setup, namely installing Nginx, creating a self-signed SSL-certificate, writing the reverse-proxy config directives and optionally starting the Nginx webserver right away. The latter requires sudo superpowers since binding to the SSL default port 443 requires root privileges. Furthermore, it makes a few assumptions:

  1. You’re using Mac and Homebrew
  2. You don’t have Nginx installed or don’t care about config files being overwritten
  3. Your Rails app is running on localhost:3000

You can download the script from Absolventa’s Github repo. Run it on your machine with bash and follow the instructions on your terminal. If you stray from the Happy Path™, feel free to send a PR our way!

comments powered by Disqus