Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use CDN with carrierwave + fog in s3 + cloudfront with rails 3.1

Tags:

I'm using fog with carrierwave in my website. But the images load very very slowly.

Then I want to speed up loading of images with a CDN.

I have followed this tutorial for create the CDN for images:

http://maketecheasier.com/configure-amazon-s3-as-a-content-delivery-network/2011/06/25

I have now my distribution deployed for images but I don't know how works fine the cdn. I have in initializers/fog.rb the next configuration:

CarrierWave.configure do |config|   config.fog_credentials = {     :provider               => 'AWS',     :aws_access_key_id      => 'key',     :aws_secret_access_key  => 'key',     :region                 => 'eu-west-1'   }   config.fog_host = "http://da33ii2cvf53u.cloudfront.net" #config.asset_host instead of config.fog_host for new fog gem versions   config.fog_directory  = 'pin-pro'   config.fog_public     = false   #config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}  end  

I dont know if this is correct, but in my local machine it does not works fine for me. I see the image location, is the same route as before:

https://s3-eu-west-1.amazonaws.com/pin-pro/uploads/pins/medium_610cafbe-5d43-4223-ab0e-daa4990863c4.jpg?AWSAccessKeyId=AKIAIDX34WHYKB3ZKFVA&Signature=RwQriNpiRXaTxyfYVvYjsvclUa8%3D&Expires=1333203059 

How can I add a CDN to fog file in carrierwave with s3 and cloudfront?

like image 317
hyperrjas Avatar asked Mar 31 '12 14:03

hyperrjas


People also ask

Can I use S3 as CDN?

As first i would like to explain that Amazon S3 is the cloud Storage and Cloud Front is the content delivery network (CDN). So you can use to store the files on S3 and can create the distribution to serve the content over the internet. As well as you can create distribution for the specific regions.

Can objects in S3 be delivered by Amazon CloudFront?

Objects in S3 can be delivered through Amazon CloudFront.

What is S3 and CloudFront?

Amazon CloudFront works with S3 but copies files from S3 to the outer "edge" of Amazon's servers, allowing for fast retrieval. My tests show that it retrieves files in about half the time of S3. There's a slight increase in price from Amazon S3, but not much.


1 Answers

It looks like you haven't added the line below to your config. You will need to replace the sample address below with your cloudfront address from Amazon.

From the github README: https://github.com/jnicklas/carrierwave

"You can optionally include your CDN host name in the configuration. This is highly recommended, as without it every request requires a lookup of this information"

config.asset_host = "http://c000000.cdn.rackspacecloud.com"

like image 179
Paul Pettengill Avatar answered Oct 26 '22 02:10

Paul Pettengill