如何仅将Cloudfront访问限制为我的域?

时间:2018-06-23 15:45:50

标签: amazon-web-services amazon-cloudfront

我需要找到解决方法。基本上我只有一个.m3u8视频,我想限制它只能在我的域中播放。基本上,人们现在正在做什么,就是在偷我的视频并在他们的网站上播放,这会导致超载和大量带宽...

d23ek3kf.cloudfront.net/video.m3u8> mydomain.com>视频可访问

d23ek3kf.cloudfront.net/video.m3u8> randomdomain.com>无法访问视频

2 个答案:

答案 0 :(得分:0)

方法是使用签名的URL。您的网站将为用户要播放的正在播放的视频生成签名的URL,而Cloudfront则允许下载内容。签名的URL将在指定的时间后失效。

任何其他网站上都只有他的视频链接,不足以下载该视频。在此处查看AWS文档,以了解实现它的详细信息和机制。 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html

答案 1 :(得分:0)

此解决方案不会阻止任何人下载您的内容并将其上传到自己的网站,但可以防止其他网站将其热链接到您的内容。

创建一个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' }],
    }
  });
};
相关问题