Monday, July 01, 2013

How to Setup Amazon Cloud Front in Rails 3.2 app


I bought my domain at namecheap.com. It is hosted at Linode.

Step 1 : I used Linode control panel to create a CNAME. It looks like this:

CNAME Records
Hostname Aliases to TTL
cdn amazon-provided-id.cloudfront.net Default
www clickplan.net Default

Step 2 : Go to Amazon Cloud Front and setup a CDN distribution. I followed the instructions from this blog: http://happybearsoftware.com/use-cloudfront-and-the-rails-asset-pipeline-to-speed-up-your-app.html

Note that you should also provide alternate domain name. In my case it was cdn.clickplan.net.

Step 3 : In production.rb add :

  config.action_controller.asset_host = "amazon-provided-id.cloudfront.net"

You can also setup a CNAME like cdn.yourdomain.com to point to amazon-provided-id.cloudfront.net. I am using https for the entire site. Since I did not have wildcard SSL certificate, it did not work so I am using https://amazon-provided-id.cloudfront.net for now. Amazon also has a documentation that shows how to use SSL with your cname. If you have issues, make sure you clear all the history in the browser and hit the URL to see if you can view the css and javascript.