将CDN与s3中的载波+雾+在Rails 3.1中使用Cloudfront一起使用 [英] Use CDN with carrierwave + fog in s3 + cloudfront with rails 3.1

查看:113
本文介绍了将CDN与s3中的载波+雾+在Rails 3.1中使用Cloudfront一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站中将 carrierwave 一起使用.但是图像加载非常缓慢.

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

然后我想通过CDN加快图像加载速度.

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

我已按照本教程为图像创建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

我现在已经为图像部署了发行版,但我不知道CDN的工作情况如何.我在initializers/fog.rb中具有下一个配置:

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

如何在带有s3和cloudfront的载波中将CDN添加到雾文件中?

推荐答案

您似乎尚未在配置中添加以下行.您需要将以下示例地址替换为来自Amazon的Cloudfront地址.

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.

从github自述文件: https://github.com/jnicklas/carrierwave

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

您可以选择在配置中包括您的CDN主机名.强烈建议您这样做,因为没有它,每个请求都需要查找此信息".

"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"

这篇关于将CDN与s3中的载波+雾+在Rails 3.1中使用Cloudfront一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆