SSL for Ruby on Rails app

When pummeling around this problem I figured out there are not many step-by-step tutorials for dummies (like me). So after fixing all issues, I think it’s good practice to share the knowledge.

How to set up SSL for your rails application

Step 1: Obtain the SSL certificate. Various providers offer them. A certificate is, simply put, a bunch of text. It is divided into few parts. Usually two or four. The first one is the key. The second one is the actual certificate. It might be split into three separate files.

Step 2: Place those files on your server. I put them inside the Nginx directory (/etc/nginx/ssl/project_name/certificate.crt – for the certificate and /etc/nginx/ssl/project_name/certificate.key – for the key) Be sure, to concatenate your certificate the right way. If it’s not concatenated yet, take care of combining them together with, the right way – there is always a middle part, a prefix, and a suffix part. Putting middle part at the end will cause the file to malfunction.

Example of the certificate file

Step 3: Configure Nginx. My example is listed below. It shows how you can run both versions, http and https at the same time. Additionally, I included a redirect, so my client doesn’t need to buy certificates for each similar domain.

I’m almost sure that this is the most basic and ineffective approach, but it’s working quite well.