Adding SSL to Your Rails 4 App

There are a few different ways you can configure ssl into your rails app. I prefer the options where the least amount of configurations are required. The following is an example of getting a particular page in your rails app to handle things like purchasing with a secure protocol in nginx.

First create a folder in your etc/ssl directory and name it localcerts.

Then go into that folder and generate a self signed certificate that you will later send to an SSL provider with the following commands:

Once your SSL provider sends you the signed certificate, add it to your localcerts folder.

Now add the following to your nginx.conf file below the default server listening on port 80:


If your server won’t restart, run the following to debug:

Now you can see if your server accepts https requests by prefixing any page on your site with it.

If everything is in order go to the controller of the page that you want secured and add the following:

The first part will require an https connection on all actions in that controller and you can pass in options to specify the actions you want to require an https connection with the second part. See the documentation here.

The latter part restricts ssl to the production environment.

Now the last thing you have to do is change the routes in your headers, footers, or sidebars that are linked from the secured page with the url_path helper to something like:

This ensures that all the pages you do not want served over an ssl connection to be served via http.

That’s it! Now you’re ready to start accepting payments and adding users to your production app!

Here is also a tutorial to set your conf file for a wordpress blog.

Related Posts

Deploy a Rails App with Heroku It's easy as pie to push a demo version of your rails app to heroku. Follow the simple steps below and you'll be on your way to testing in a subdomain...
Adding a WordPress Blog to Your Rails App If you're running a rails application with a blog like I was, you we're probably using something that utilized jekyl. There are some good blogging pla...

David Chun

I'm a full stack developer that builds tools for marketing and managing ecommerce shops. I occasionally consult for startups. If you've got an interesting project, reach out.


One thought on “Adding SSL to Your Rails 4 App

Leave a Reply

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