Rails Cloudfront 和 s3 上的 AWS 资产

Rails AWS assets on Cloudfront & s3

所以我将回形针设置为与 S3 一起使用以在上传时存储图像。工作正常。

然后我去为资产添加云端(使用下面的代码)

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

并构建资产,它似乎构建了所有正确的内容,但每当我转到该页面时,link 就在那里

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

但是当我去 link 我得到这个 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>

我看了看我的s3盒子,也没有..

我所有的云端设置都是默认的,除了我的来源是我的 s3 盒子

要让 Cloudfront 从 s3 获取您的资产,您需要将资产复制到 s3。一个流行的选择是 asset_sync gen,它将作为部署的一部分执行此操作。

另一种选择是让云端从您的服务器获取资产——这需要向云端分发添加新的来源和行为。