简体   繁体   English

Amazon S3上的静态托管 - DNS配置

[英]Static hosting on Amazon S3 - DNS Configuration

I'm working on a little webapp (all client-side) I want to host it on Amazon S3. 我正在开发一个小型webapp(所有客户端)我想在Amazon S3上托管它。 I've found several guides on this and have managed to create myself a bucket (with the same name as my domain), set it as a website and upload some content. 我已经找到了几个这方面的指南,并设法创建了一个桶(与我的域名相同),将其设置为网站并上传一些内容。

Where I'm struggling, and where all the documentation starts to get a bit vague, is how to properly configure my DNS. 在我努力的地方,以及所有文档开始变得有点模糊的地方,是如何正确配置我的DNS。

All my registrar ( 123-reg ) could suggest was web forwarding which gives me mydomain.com.s3.amazonaws.com 我的所有注册商( 123-reg )都可以建议网络转发给我mydomain.com.s3.amazonaws.com

What do I have to configure, and where (ie. 123-reg / Amazon) can I get a clean URL? 我需要配置什么,以及在哪里(即123-reg / Amazon)可以获得干净的URL?

Sounds like you've done most of the work already. 听起来你已经完成了大部分工作。 For clarity I'll go over those steps again just to make sure you're set up properly: 为清楚起见,我会再次检查这些步骤,以确保您的设置正确:

  1. Create an s3 bucket using your domain name as the bucket name (your bucket name should be www.example.com if you want your site to be example.com or www.example.com) 使用您的域名作为存储桶名称创建一个s3存储桶(如果您希望您的网站是example.com或www.example.com,您的存储桶名称应为www.example.com)

  2. Upload your content to the s3 bucket. 将您的内容上传到s3存储桶。 Choose a consistent name for your website index files (index.html usually). 为您的网站索引文件选择一致的名称(通常是index.html)。 You can also upload a custom page for 404 Not Found errors. 您还可以上传404 Not Found错误的自定义页面。 Call this 404.html. 请拨打404.html。 Give Read permissions to every file in your website so that the public can view it. 为您网站中的每个文件授予读取权限,以便公众可以查看它。 Don't give any extra permissions to the bucket, just the files within. 不要对存储桶提供任何额外的权限,只包括其中的文件。

  3. Configure your bucket as a website. 将您的存储桶配置为网站。 With the AWS console ( https://console.aws.amazon.com/s3/ ) you can select your bucket, click properties, then select the "Website" tab. 使用AWS控制台( https://console.aws.amazon.com/s3/ ),您可以选择存储桶,单击属性,然后选择“网站”选项卡。 Click enabled and set your index document to "index.html" and your error document to "404.html". 单击“启用”并将索引文档设置为“index.html”,将错误文档设置为“404.html”。 You will also need to set your bucket with access permissions to allow access via the web ( http://docs.amazonwebservices.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html ) 您还需要设置具有访问权限的存储桶,以允许通过Web访问( http://docs.amazonwebservices.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html

  4. Take a note of the "Endpoint" URL in the website configuration tab. 记下网站配置选项卡中的“端点”URL。 This is where your website lives. 这是您网站的所在地。 You can open the link in a new window and you should see your website just as it will look. 您可以在新窗口中打开链接,您应该看到您的网站。 Click around and make sure everything works as expected. 单击并确保一切按预期工作。

You MUST use the endpoint address in all steps below. 您必须在以下所有步骤中使用端点地址。 The normal www.example.com.s3.amazonaws.com won't work - you need to use the regional version ( http://www.example.com.s3-website-us-east-1.amazonaws.com/ ) 正常的www.example.com.s3.amazonaws.com无法使用 - 您需要使用区域版本( http://www.example.com.s3-website-us-east-1.amazonaws.com/

Now, we can set up the DNS to give you a clean, custom URL. 现在,我们可以设置DNS以为您提供干净的自定义URL。

First, we will map www.example.com to your site. 首先,我们会将www.example.com映射到您的网站。

Using your DNS provider's tools, (123-reg in your case) you need to create a CNAME record to map www.example.com to www.example.com.s3-website-us-east-1.amazonaws.com 使用DNS提供商的工具(在您的情况下为123-reg),您需要创建CNAME记录以将www.example.com映射到www.example.com.s3-website-us-east-1.amazonaws.com

The CNAME is the only thing you need if you just want www.example.com. 如果您只是想要www.example.com,那么CNAME是您唯一需要的。 Most people also want "example.com" to work so we need another step. 大多数人也希望“example.com”工作,所以我们需要另一步。

example.com is often referred to as a naked domain or the apex record of the domain. example.com通常被称为裸域或域的顶点记录。 The reason it's a problem is that it can't be a CNAME. 这是一个问题的原因是它不能是CNAME。 CNAMEs only work on subdomains like "www." CNAME仅适用于“www”等子域。 This makes it more difficult to point at s3. 这使得指向s3变得更加困难。

The usual approach is to use a service to automatically redirect any request going to example.com to point to www.example.com. 通常的方法是使用服务自动将任何发送到example.com的请求重定向到指向www.example.com。 This will then pick up your CNAME record and your site will be served from s3. 然后,这将获取您的CNAME记录,您的网站将从s3提供。

The automatic redirect is not possible with plain old DNS so you have to use another service. 使用普通旧DNS无法实现自动重定向,因此您必须使用其他服务。 Some DNS providers offer this service along with their DNS (godaddy does, amazon route53 does not. Not sure about 123-reg) 一些DNS提供商提供此服务以及他们的DNS(godaddy确实如此,amazon route53没有。不确定123-reg)

If your DNS provider doesn't do it, there are a few free services. 如果您的DNS提供商不这样做,那么有一些免费服务。 One that I've used is http://wwwizer.com/naked-domain-redirect - it doesn't require any registration or payment. 我使用的是http://wwwizer.com/naked-domain-redirect - 它不需要任何注册或付款。

To use this type of service, you need to create a DNS "A" record for your naked domain. 要使用此类服务​​,您需要为裸域创建DNS“A”记录。 For the wwwizer.com service, you would need to create an A record to point example.com to 174.129.25.170. 对于wwwizer.com服务,您需要创建A记录以将example.com指向174.129.25.170。 That's all! 就这样!

So, with this setup, if a user types example.com into their browser, the following would happen: 因此,使用此设置,如果用户在其浏览器中键入example.com,则会发生以下情况:

  1. DNS query: example.com -> 174.129.25.170 (wwwizer.com's service) DNS查询:example.com - > 174.129.25.170(wwwizer.com的服务)
  2. HTTP request to 174.129.25.170 for example.com 对example.com的174.129.25.170的HTTP请求
  3. 174.129.25.170 redirects example.com -> www.example.com 174.129.25.170重定向example.com - > www.example.com
  4. DNS query: www.example.com -> CNAME to www.example.com.s3-website-us-east-1.amazonaws.com DNS查询:www.example.com - > CNAME到www.example.com.s3-website-us-east-1.amazonaws.com
  5. DNS query: www.example.com.s3-website-us-east-1.amazonaws.com -> points to Amazon S3 DNS查询:www.example.com.s3-website-us-east-1.amazonaws.com - >指向Amazon S3
  6. HTTP request for www.example.com is now served by Amazon S3 现在,Amazon S3会为www.example.com提供HTTP请求

Enjoy! 请享用!

I believe you must select all docs in your bucket, right click, and choose "Make Public". 我相信您必须选择存储桶中的所有文档,右键单击,然后选择“公开”。 You must do this every time something changes in the bucket as well. 每次桶中的某些变化时,您都必须这样做。 I then usually right click on bucket, choose properties, choose permissions in right hand pane then add "Everyone as a "grantee" then give them only "list" permissions. The rest of your article is excellent. The part about the naked domain helped me resolve my issues. You can also have the naked domain redirected to the www domain within S3 under "Static Website Hosting" It's probably the easiest way. Thanks again for all your help. 然后我通常右键单击存储桶,选择属性,在右侧窗格中选择权限,然后添加“Everyone as a”grantee“,然后只给它们”list“权限。你的文章的其余部分非常好。关于裸域的部分帮助我可以解决我的问题。您也可以将裸域重定向到S3中“静态网站托管”下的www域。这可能是最简单的方法。再次感谢您的帮助。

Tim 蒂姆

From the Advanced DNS screen on your 123-reg control panel 从123-reg控制面板上的高级DNS屏幕

  • I started by clicking the "Reset DNS" button to the default 123-reg settings. 我首先点击“重置DNS”按钮,进入默认的123-reg设置。

This gave me the following; 这给了我以下内容;

DNS Entry Type Priority TTL Destination/Target DNS条目 类型 优先级 TTL 目的地/目标
* A * A.                      81.xx.xx.xx 81.xx.xx.xx
@ A @ A                      81.xx.xx.xx 81.xx.xx.xx
@ MX 10 @ MX 10          xx0.123-reg.co.uk xx0.123-reg.co.uk
@ MX 20 @ MX 20          xx1.123-reg.co.uk xx1.123-reg.co.uk

  • I then added this entry 然后我添加了这个条目

www CNAME www CNAME                      www.example.com.s3-website-us-east-1.amazonaws.com www.example.com.s3-website-us-east-1.amazonaws.com

From their Manage DNS guide pdf it says the "@ record" refers to "your domain in its purest form with no subdomain" ie the naked domain stackoverflow.com 从他们的管理DNS指南pdf中可以看出,“@ record”是指“你的域名是最纯粹的,没有子域名”,即裸域stackoverflow.com

But it doesn't mention what the "* record" is, I assumed it would be to catch all sub domains and thought it might over ride the CNAME record but this does not appear to be the case. 但它没有提到“*记录”是什么,我认为它将捕获所有子域并认为它可能超过CNAME记录,但事实并非如此。

Update 2019 更新2019年

As of today following DNS setting worked for me to get AWS S3 static website working : 截至今天,随着DNS设置让我使AWS S3静态网站正常工作:

存储桶映射的DNS设置

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

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