Amazon S3 上的静态托管 - DNS 配置 [英] Static hosting on Amazon S3 - DNS Configuration

查看:57
本文介绍了Amazon S3 上的静态托管 - DNS 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小网络应用程序(所有客户端),我想将它托管在 Amazon S3 上.我找到了几个关于此的指南,并设法为自己创建了一个存储桶(与我的域同名),将其设置为网站并上传一些内容.

I'm working on a little webapp (all client-side) I want to host it on 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.

我正在苦苦挣扎的地方,以及所有文档开始变得有点模糊的地方,是如何正确配置我的 DNS.

Where I'm struggling, and where all the documentation starts to get a bit vague, is how to properly configure my DNS.

我所有的注册商 (123-reg) 都建议是网络转发,这给了我 mydomain.com.s3.amazonaws.com

All my registrar (123-reg) could suggest was web forwarding which gives me mydomain.com.s3.amazonaws.com

我必须配置什么,以及在哪里(即 123-reg/Amazon)可以获得干净的 URL?

What do I have to configure, and where (ie. 123-reg / Amazon) can I get a clean 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. 使用您的域名作为存储桶名称创建一个 s3 存储桶(如果您希望您的站点是 example.com 或 www.example.com,则您的存储桶名称应该是 www.example.com)

  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 存储桶.为您的网站索引文件选择一个一致的名称(通常是 index.html).您还可以为 404 Not Found 错误上传自定义页面.将此称为 404.html.为您网站中的每个文件授予读取权限,以便公众可以查看.不要给存储桶任何额外的权限,只给里面的文件.

Upload your content to the s3 bucket. Choose a consistent name for your website index files (index.html usually). You can also upload a custom page for 404 Not Found errors. Call this 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.

将您的存储桶配置为网站.通过 AWS 控制台 ( https://console.aws.amazon.com/s3/ ),您可以选择您的存储桶,单击属性,然后选择网站"选项卡.单击启用并将您的索引文档设置为index.html"并将您的错误文档设置为404.html".您还需要为您的存储桶设置访问权限,以允许通过 Web (http://docs.amazonwebservices.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html)

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. Click enabled and set your index document to "index.html" and your error document to "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)

记下网站配置选项卡中的端点"URL.这是您的网站所在的位置.您可以在新窗口中打开链接,您应该会看到您的网站.点击周围并确保一切正常.

Take a note of the "Endpoint" URL in the website configuration tab. 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.

您必须在以下所有步骤中使用端点地址.正常的 www.example.com.s3.amazonaws.com 将不起作用 - 您需要使用区域版本 (http://www.example.com.s3-website-us-east-1.amazonaws.com/)

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/)

现在,我们可以设置 DNS 为您提供一个干净的自定义 URL.

Now, we can set up the DNS to give you a clean, custom URL.

首先,我们会将 www.example.com 映射到您的网站.

First, we will map www.example.com to your site.

使用您的 DNS 提供商的工具(在您的情况下为 123-reg),您需要创建 CNAME 记录以将 www.example.com 映射到 www.example.com.s3-website-us-east-1.amazonaws.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

如果您只想要 www.example.com,CNAME 是您唯一需要的东西.大多数人还希望example.com"能够正常工作,因此我们还需要再进一步.

The CNAME is the only thing you need if you just want www.example.com. Most people also want "example.com" to work so we need another step.

example.com 通常被称为裸域或域的顶级记录.这是一个问题的原因是它不能是 CNAME.CNAME 仅适用于www"等子域.这使得指向 s3 变得更加困难.

example.com is often referred to as a naked domain or the apex record of the domain. The reason it's a problem is that it can't be a CNAME. CNAMEs only work on subdomains like "www." This makes it more difficult to point at s3.

通常的方法是使用服务自动将任何去往 example.com 的请求重定向到 www.example.com.然后,这将获取您的 CNAME 记录,您的网站将从 s3 提供服务.

The usual approach is to use a service to automatically redirect any request going to example.com to point to www.example.com. This will then pick up your CNAME record and your site will be served from s3.

使用普通的旧 DNS 无法自动重定向,因此您必须使用其他服务.一些 DNS 提供商在其 DNS 中提供此服务(godaddy 提供,amazon route53 没有.不确定 123-reg)

The automatic redirect is not possible with plain old DNS so you have to use another service. Some DNS providers offer this service along with their DNS (godaddy does, amazon route53 does not. Not sure about 123-reg)

如果您的 DNS 提供商不这样做,则有一些免费服务.我使用过的一个是 http://wwwizer.com/naked-domain-redirect - 它不需要任何注册或付款.

If your DNS provider doesn't do it, there are a few free services. One that I've used is http://wwwizer.com/naked-domain-redirect - it doesn't require any registration or payment.

要使用此类服务​​,您需要为您的裸域创建 DNSA"记录.对于 wwwizer.com 服务,您需要创建 A 记录以将 example.com 指向 174.129.25.170.就这些!

To use this type of service, you need to create a DNS "A" record for your naked domain. For the wwwizer.com service, you would need to create an A record to point example.com to 174.129.25.170. That's all!

因此,通过此设置,如果用户在浏览器中输入 example.com,则会发生以下情况:

So, with this setup, if a user types example.com into their browser, the following would happen:

  1. DNS 查询:example.com -> 174.129.25.170(wwwizer.com 的服务)
  2. HTTP 请求到 174.129.25.170 for example.com
  3. 174.129.25.170 重定向 example.com -> www.example.com
  4. DNS 查询:www.example.com -> CNAME 到 www.example.com.s3-website-us-east-1.amazonaws.com
  5. DNS 查询:www.example.com.s3-website-us-east-1.amazonaws.com -> 指向 Amazon S3
  6. 对 www.example.com 的 HTTP 请求现在由 Amazon S3 提供服务

享受吧!

这篇关于Amazon S3 上的静态托管 - DNS 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆