rol*_*ele 9 amazon-s3 amazon-cloudfront amazon-route53
我创建了一个AOI来限制s3存储桶对公众的访问.因此,您无法通过s3端点访问s3对象,但cloudfront可以访问所有这些对象并为其提供服务.
我设置了备用域名,并为此域添加了SSL证书.
我使用A规则设置路由53以对云端分布进行别名
我可以使用Cloudfront公共网址(*.cloudfront.net)和mydomain.com访问该网页
如何删除*.cloudfront.net访问我的页面?这应该是可能的,因为需要此URL的唯一服务是路由53.
您可以使用 Lambda@Edge 查看器请求触发器。这允许您在检查缓存之前检查请求,并允许处理继续或返回生成的响应。
因此,您可以检查引荐来源网址并确保请求来自您的域。
'use strict';
exports.handler = (event, context, callback) => {
// extract the request object
const request = event.Records[0].cf.request;
// extract the HTTP `Referer` header if present
// otherwise an empty string to simplify the matching logic
const referer = (request.headers['referer'] || [ { value: '' } ])[0].value;
// verify that the referring page is yours
// replace example.com with your domain
// add other conditions with logical or ||
if(referer.startsWith('https://example.com/') ||
referer.startsWith('http://example.com/'))
{
// return control to CloudFront and allow the request to continue normally
return callback(null,request);
}
// if we get here, the referring page is not yours.
// generate a 403 Forbidden response
// you can customize the body, but the size is limited to ~40 KB
return callback(null, {
status: '403',
body: 'Access denied.',
headers: {
'cache-control': [{ key: 'Cache-Control', value: 'private, no-cache, no-store, max-age=0' }],
'content-type': [{ key: 'Content-Type', value: 'text/plain' }],
}
});
};
Run Code Online (Sandbox Code Playgroud)
欲了解更多信息,请阅读以下页面:
最后,这篇文章有很多有价值的信息
如何使用 AWS WAF、Amazon CloudFront 和引用检查来防止热链接
| 归档时间: |
|
| 查看次数: |
664 次 |
| 最近记录: |