我正在使用 aws s3 来存储我的网站图片和视频内容。来自 s3 的文件链接直接输出到 html/php。
问题是其他一些网站链接了我的图片/视频,这大大增加了 s3 流量使用,当然也增加了工资单。
我知道在某些情况下人们使用引用 header 来禁止外部站点链接。但在这种情况下,图片/视频直接从 s3 出去,而不是我的域。
有人可以帮助实现这一目标吗?谢谢。
最佳答案
您可以使用 Amazon 存储桶策略,例如:
{
"Version": "2012-10-17",
"Id": "http referer policy example",
"Statement": [
{
"Sid": "Allow get requests originated from www.example.com and example.com",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::examplebucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://www.example.com/*",
"http://example.com/*"
]
}
}
}
]
}
详细解释在:http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
关于amazon-s3 - 如何仅允许 aws s3 存储桶内容公开服务于某个域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9313781/