Using Amazon Cloudfront CDN with Rails App


Learn how to setup CDN using Amazon Cloudfront for Rails Apps.


Step 1

Go to Amazon Cloud Front and setup a CDN distribution. Click Cloud Front, provide the hostname
and accept the default values for other values. It will take about 15 to 30 minutes for the changes to take effect.

Amazon Cloudfront CDN

Step 2

In production.rb add :

 config.action_controller.asset_host = ""

You can also setup a CNAME like to point to I am using https for the entire site. Since I did not have wildcard SSL certificate, it did not work. So, I am using for now.

Step 3

After deploying your Rails app, view the page source. Verify the CDN. You should now see CDN for static assets. Something like this:


It took me half hour to setup CDN using Amazon Cloudfront for Ruby Plus. You can use WebPageTest to check the performance of your site before and after using CDN.

Web Page Test

Related Articles

Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.