简体   繁体   English

在Cloudfront和S3上使用Rails AWS资产

[英]Rails AWS assets on Cloudfront & s3

So I setup paperclip to work with S3 to store images on upload. 因此,我设置了回形针以与S3配合使用以在上传时存储图像。 That is working fine. 很好

I then went to add cloudfront for assets (with the code below) 然后,我去添加Cloudfront资产(使用下面的代码)

config.action_controller.asset_host = ENV['CLOUDFRONT_ENDPOINT']

and build the assets, it seems to build all correctly and everything, but whenever I go to the page the links are there 并构建资产,似乎可以正确构建所有内容,但是每当我转到页面时,链接就在那里

<link rel="stylesheet" media="all" href="http://d2j2dcfn0tfw0d.cloudfront.net/assets/application-ef64d41d2d57abb59ffe5bd71a4f727580ef276a6440e70210cf8d0ab22a6dc2.css" />
<script src="http://d2j2dcfn0tfw0d.cloudfront.net/assets/application-8cd15647254a9c6f940c58bcae0567e6ca66943b8a7576ce87ec903bd19f9937.js"></script>

but when I go to that link i get this XML error 但是当我转到该链接时,出现此XML错误

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>
assets/application-ef64d41d2d57abb59ffe5bd71a4f727580ef276a6440e70210cf8d0ab22a6dc2.css
</Key>
<RequestId>374DF77BF548DE75</RequestId>
<HostId>
TqrV7id3elsBjugWNkUObG259mU6Vk8MhxcXjrre1qv+XvxGBERDjWoW50iiCyp4
</HostId>
</Error>

I looked at my s3 box and it's not there either.. 我看着我的s3盒子,它也不在那里。

All my cloudfront settings were default except my origin which was my s3 box 除我的原点即我的s3框外,我所有的cloudfront设置都是默认设置

For cloudfront to fetch your assets from s3 you need to copy the assets to s3. 为了使Cloudfront从s3获取资产,您需要将资产复制到s3。 A popular choice for this is the asset_sync gen which will do this as part of deploys. 一个流行的选择是asset_sync gen,它将作为部署的一部分进行。

Another option is to let cloudfront fetch the assets from your server - this requires adding a new origin and behaviour to the cloudfront distribution. 另一个选择是让Cloudfront从您的服务器中获取资产-这需要向Cloudfront发行中添加新的来源和行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM