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

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

问题描述

我正在一个webapp(所有客户端)上工作,我想在Amazon S3上托管它。我已经找到了几个指南,并设法创建了一个桶(与我的域名相同),将其设置为网站并上传一些内容。



我在哪里努力,所有的文档开始变得有点模糊,是如何正确配置我的DNS。



我所有的注册商( 123-reg )可以建议是web转发给我mydomain.com.s3.amazonaws.com



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

解决方案

听起来你已经完成了大部分的工作。为了清楚起见,我将再次讨论这些步骤,以确保您的设置正确:


  1. 创建一个s3桶使用您的域名作为存储桶名称(如果您希望您的网站为example.com或www.example.com,您的存储桶名称应为www.example.com)


  2. 将您的内容上传到s3桶。为您的网站索引文件(通常为index.html)选择一致的名称。您还可以上传自定义页面以查找404未找到错误。叫这个404.html。为您的网站中的每个文件授予阅读权限,以便公众可以查看它。不要给桶添加任何额外的权限,只有文件内容。


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


  4. 在网站配置标签中记下端点URL 。这是你的网站所在。您可以在新窗口中打开链接,您应该看到您的网站。点击周围,确保一切正常工作。


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



现在,我们可以设置DNS给你一个干净的自定义URL。



首先,我们将把www.example.com映射到你的站点。 >

使用您的DNS提供商的工具(在您的情况下为123-reg),您需要创建一个CNAME记录,将www.example.com映射到www.example.com.s3网站-us-east-1.amazonaws.com



如果您只想www.example.com,CNAME是唯一需要的。大多数人也希望example.com工作,所以我们需要另一个步骤。



example.com通常被称为裸域或域的顶点记录。这是一个问题的原因是它不能是CNAME。 CNAME只能在www等子域上工作。这使得在s3上更难点。



通常的方法是使用服务自动重定向到example.com的任何请求来指向www.example。 COM。然后,您将收到您的CNAME记录,您的网站将从s3发送。



使用纯旧的DNS不能自动重定向,因此您必须使用其他服务。一些DNS提供商提供这个服务及其DNS(Godaddy确实,亚马逊route53没有,不确定123-reg)



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



要使用这种类型的服务,您需要为裸域创建DNSA记录。对于wwwizer.com服务,您需要创建一个A记录,将example.com指向174.129.25.170。所以,如果用户使用这个设置,如果用户在浏览器中输入example.com,将会发生以下情况:


  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 - >指向亚马逊S3

  6. www.example.com的HTTP请求现在由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.

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

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

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

  2. 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.

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

  4. 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.

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

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

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

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

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 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.

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.

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)

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.

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!

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

  1. DNS query: example.com -> 174.129.25.170 (wwwizer.com's service)
  2. HTTP request to 174.129.25.170 for example.com
  3. 174.129.25.170 redirects example.com -> www.example.com
  4. DNS query: www.example.com -> CNAME to 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
  6. HTTP request for www.example.com is now served by Amazon S3

Enjoy!

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

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