简体   繁体   English

如何通过CNAME将Netlify子域指向AWS S3存储桶?

[英]How to point a Netlify subdomain to an AWS S3 bucket via CNAME?

I have a static site ( mysite.com ) hosted via Netlify. 我有一个通过Netlify托管的静态网站( mysite.com )。 Netlify currently manages my DNS, so that I have nameservers like so: Netlify目前管理我的DNS,所以我有这样的名字服务器:

  • dns1.p07.nsone.net
  • dns2.p07.nsone.net
  • dns3.p07.nsone.net
  • dns4.p07.nsone.net

I have a bucket on my S3 named dl.mysite.com . 我的S3上有一个名为dl.mysite.com的存储桶。 I want to have it so that when somebody clicks a link such as http://dl.mysite.com/file.pdf , it grabs it from the S3 bucket. 我想拥有它,以便当有人点击http://dl.mysite.com/file.pdf等链接时,它会从S3存储桶中http://dl.mysite.com/file.pdf它。

Within my management dashboard for Netlify, I'm able to create a custom subdomain ( dl.mysite.com ), and it directs me to do the following: 在我的Netlify管理仪表板中,我可以创建一个自定义子域( dl.mysite.com ),它指示我执行以下操作:

Point dl CNAME record to obfuscated-url-d6f26e.netlify.com Log in to the account you have with your DNS provider, and add a CNAME record for dl pointing to obfuscated-url-d6f26e.netlify.com . dl CNAME记录指向obfuscated-url-d6f26e.netlify.com登录您的DNS提供商所拥有的帐户,并为dl添加指向obfuscated-url-d6f26e.netlify.com的CNAME记录。

In the past, when I used AWS exclusively to host the app and manage DNS, this was easily accomplished by just creating an Alias record in Route53 for the subdomain and pointing it to my bucket. 过去,当我专门使用AWS来托管应用程序并管理DNS时,只需在Route53中为子域创建别名记录并将其指向我的存储桶即可轻松完成。

How can I accomplish this now that Route53 doesn't handle my DNS? 如果Route53不处理我的DNS,我怎么能做到这一点? Is it still possible to point that subdomain at a particular S3 bucket? 是否仍然可以将该子域指向特定的S3存储桶?

disclaimer: I work for Netlify. 免责声明:我为Netlify工作。

Netlify is intended to host web content, not proxy entirely to S3 buckets. Netlify旨在托管Web内容,而不是完全代理S3存储桶。 Using it as you describe may work but is against our terms of service which specifically state that we intend to host websites with html content for people to browse, not computers. 在您描述的情况下使用它可能有效,但违反了我们的服务条款,条款明确规定我们打算托管具有html内容的网站供人们浏览,而不是计算机。 If that is literally all you want to do - serve content out of that S3 bucket, then I wouldn't bother with the intermediate step of using Netlify at all here. 如果这就是你想要做的所有 - 从S3桶中提供内容,那么我就不会在这里完全使用Netlify的中间步骤了。 It's another point of failure that doesn't buy you much to put us between your visitors and S3. 这是另一个失败点,对我们介绍访问者和S3之间没什么好处。 One more reasonable way to do it is the way @thomas above suggested. 另一种合理的方法是@thomas上面建议的方式。

However, if you want to use Netlify's DNS hosting for your domain since we host other site(s) for you, you can absolutely still use our DNS to set up a hostname that points directly to S3 - no terms of service violation there as we don't limit your use of our DNS service. 但是,如果您因为我们为您托管其他网站而想为您的域使用Netlify的DNS托管,您绝对仍然可以使用我们的DNS设置直接指向S3的主机名 - 我们没有违反服务条款的条款不要限制您使用我们的DNS服务。 Many customers have us host DNS for domains where there is one website on netlify and a dozen elsewhere. 许多客户让我们为netlify上有一个网站和其他地方有十几个网站的域提供DNS。 To configure this, I'd instead set that record as a CNAME to the S3 hostname, and handle any SSL certificate on AWS' side. 为了配置它,我将该记录设置为S3主机名的CNAME,并处理AWS方面的任何SSL证书。 This will work well and if it doesn't our tech support team will be happy to help you out. 这将很好,如果不是,我们的技术支持团队将很乐意帮助您。

In a third situation, if you want to serve some content at that hostname from S3 (eg PDF's) and then some other content (eg your website html files that link to PDF's), that is legit! 在第三种情况下,如果您想从S3(例如PDF)的主机名提供一些内容,然后是其他一些内容(例如链接到PDF的网站html文件),这是合法的! We'll be happy to proxy to your S3 content. 我们很乐意代理您的S3内容。 For instance, you can set up a (reverse) proxy to /files/* on S3 like this, in a /_redirects file: 例如,您可以在/_redirects文件中为S3上的/files/*设置(反向)代理:

/files/* http://aws-bucket-hostname/:splat 200!

This says "load all files from Netlify EXCEPT /files/* which should instead come from S3 with a path matching the part after /files/ in the URL". 这说“从Netlify EXCEPT / files / *加载所有文件,而不是来自S3,其路径与URL中/ files /之后的部分相匹配”。 In this case we WILL handle the SSL certificate for you since we terminate the browser connection instead of S3. 在这种情况下,我们将为您处理SSL证书,因为我们终止了浏览器连接而不是S3。

More docs on that functionality here: 这里有关于该功能的更多文档:

https://www.netlify.com/docs/redirects/ https://www.netlify.com/docs/redirects/

In order to use Static Hosting on S3 (allowing for your bucket to be a domain name), you can only use an alias on Route 53. 为了在S3上使用静态主机(允许您的存储桶成为域名),您只能在Route 53上使用别名。

You can however use CloudFront to serve files using a domain name of your choice. 但是,您可以使用CloudFront使用您选择的域名来提供文件。

I would say your options are: 我会说你的选择是:

  1. Switch back to using Route 53 切换回使用Route 53
  2. Use CloudFront in-front of your S3 bucket 在S3存储桶前面使用CloudFront
  3. Just use the S3 bucket link 只需使用S3存储桶链接即可

(Considering how many browsers obscure the address and that people don't really care, I would go with option 3 personally .) (考虑到有多少浏览器掩盖了地址并且人们并不真正关心,我会亲自选择3。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM