title: Heroku + Rails4.2 : Cloudfront setup
body: <p>I am trying to setup Cloudfront for my heroku app. <a href="https://devcenter.heroku.com/articles/using-amazon-cloudfront-cdn#amazon-cloudfront" rel="noreferrer">The documentation</a> seems to be lacking to stand independently.</p>
  
  <p>Here are the steps I followed:</p>
  
  <pre><code> 1. Setup Cloudfront in AWS console
   2. Added cloudfront domain name to production.rb `config.action_controller.asset_host = 'XXXX.cloudfront.net'`
   3. Set `config.assets.compile = true` in production.rb
   4. Verified AWS_SECRET_ACCESS_KEY is correct in heroku config
   5. I have added `gem 'rails_12factor', group: :production`
  </code></pre>
  
  <p>None of assets load anymore. Any step I am missing in the setup?</p>
  
  <hr>
  
  <p>Update1:</p>
  
  <p>In the chrome debugger the asset is correctly requested from cloudfront from this url: <a href="http://XXXXX.cloudfront.net/assets/application-22c7c249df1a24541d86603b0715eefe.css" rel="noreferrer">http://XXXXX.cloudfront.net/assets/application-22c7c249df1a24541d86603b0715eefe.css</a></p>
  
  <p>However in the request header see a <code>Status Code:302 Moved Temporarily</code>. I am wondering if I have a redirect loop and how I can debug it. </p>
  
  <p><strong>Update2</strong></p>
  
  <p>Thanks everyone for the suggestions. Some more info:</p>
  
  <ol>
  <li>When I try to download the asset from my app, I get a redirect to home page on browser but using curl I am able to get the asset. ex: curl 'http: //www.myapp.com/assets/application-c9a778bb55ad4152d956fd34fe6f7839.css' </li>
  <li>The app doesnt use SSL. However I have still set Origin Protocol Policy to Match Viewer as per @Omar's suggestions</li>
  <li>I tried to download the asset from my app on browser and am able to access the assets. ex: 'http: //www.myapp.com/assets/application-c9a778bb55ad4152d956fd34fe6f7839.css'
  However trying to access the assets directly on cloudfront (d1ax5oefcdtdki.cloudfront.net/assets/application-c9a778bb55ad4152d956fd34fe6f7839.css) redirects it to myapp.com</li>
  <li>Screenshots for cloudfront DS:</li>
  </ol>
  
  <p><a href="https://www.dropbox.com/s/bkg480d4it6zl2r/Screenshot%202015-12-06%2014.01.28.png?dl=0" rel="noreferrer">https://www.dropbox.com/s/bkg480d4it6zl2r/Screenshot%202015-12-06%2014.01.28.png?dl=0</a></p>
  
  <p><a href="http://glui.me/?i=7ah73hffrhvmpt7/2015-12-06_at_2.02_PM.png/" rel="noreferrer">http://glui.me/?i=7ah73hffrhvmpt7/2015-12-06_at_2.02_PM.png/</a></p>
  
  <p><a href="https://www.dropbox.com/s/dd4wwgm3md8w7qn/Screenshot%202015-12-06%2014.05.20.png?dl=0" rel="noreferrer">https://www.dropbox.com/s/dd4wwgm3md8w7qn/Screenshot%202015-12-06%2014.05.20.png?dl=0</a></p>