Amazon S3静态Web托管缓存 [英] Amazon s3 static web hosting caching
问题描述
我将Amazon S3虚拟主机用于我的静态html,js,css(等)文件. 替换index.html文件后,在通过浏览器进行消费时,我仍然获得旧版本. 我想将默认ttl设置为存储桶(而不是存储桶中的特定对象).我找到了此链接: http://docs.aws.amazon .com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesDefaultTTL
I'm using Amazon S3 webhosting for my static html,js,css (etc..) files. After replacing my index.html file, I still get the old version when consuming via the browser. I would like to set a default ttl to the bucket (and not to specific objects in it). I found this link: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesDefaultTTL
,但无法在信息中心中找到对象缓存"设置.有人可以指出它在哪里吗?
but can't find the "Object Caching" setting in the dashboard. can someone point out where it is?
推荐答案
这是一个 BucketExplorer 了解更多信息.
Here's an Amazon S3 link that answers your question. According to Amazon, you can't set the cache control header for the entire bucket unless you use a third party tool (that page links to a few). One tool I ran across describes how to set the cache directives for objects submitted using a PUT
request (or in bulk using their tool). See BucketExplorer for more info.
以下是Amazon指令的摘要(因为S.O.不喜欢依赖可能更改或消失的外部链接):
Here is a cut-paste of Amazon's instructions (since S.O. doesn't like to rely on external links that might change or disappear):
使用Amazon S3控制台将Cache-Control或Expires标头字段添加到Amazon S3对象
- 登录到AWS管理控制台并打开Amazon S3控制台 在 https://console.aws.amazon.com/s3 .
- 在Amazon S3控制台的存储桶窗格中,单击包含文件的存储桶的名称.
- 在对象列表中,选择要向其添加标题字段的第一个对象.
- 点击操作,然后点击属性.
- 在右窗格中,展开元数据.
- 点击添加更多元数据.
- 在密钥列表中,单击缓存控制或过期(如果适用).
- 在值字段中,输入适用的值:
- 对于缓存控制"字段,输入:
max-age=number of seconds that you want objects to stay in a CloudFront edge cache
- 对于 Expires (到期时间)字段,以HTML格式输入日期和时间.
- 点击保存.
- Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3.
- In the Amazon S3 console, in the buckets pane, click the name of the bucket that contains the files.
- In the list of objects, select the first object to which you want to add a header field.
- Click Actions and click Properties.
- In the right pane, expand Metadata.
- Click Add More Metadata.
- In the Key list, click Cache-Control or Expires, as applicable.
- In the Value field, enter the applicable value:
- For a Cache-Control field, enter:
max-age=number of seconds that you want objects to stay in a CloudFront edge cache
- For an Expires field, enter a date and time in HTML format.
- Click Save.
如果要将标题字段添加到其他对象,请单击下一个对象的名称,然后重复步骤5到9.
If you want to add a header field to additional objects, click the name of the next object, and repeat steps 5 through 9.
这篇关于Amazon S3静态Web托管缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!