简体   繁体   English

使用Namecheap DNS进行Amazon S3静态托管 - 如何正确路由非www前缀URL

[英]Amazon S3 static hosting with Namecheap DNS - How to correctly route non-www prefixed url

I have been reading other posts to try to get down to the bottom of this issue... but I need some clarification. 我一直在阅读其他帖子,试图深入到这个问题的底部......但我需要一些澄清。

I am able to get all of my domain requests to hit my Amazon S3 bucket perfectly when entering www.FOO.com/MyDirectory 进入www.FOO.com/MyDirectory时,我能够完全获得所有域名请求以完全访问我的Amazon S3存储桶

If I enter FOO.com/MyDirectory without the www it will fail. 如果我在没有www的情况下输入FOO.com/MyDirectory,它将失败。

What is the proper method to make url requests without the www route correctly to the same Amazon S3 bucket? 在没有www路由的情况下将URL请求正确地发送到同一个Amazon S3存储桶的正确方法是什么?

Any tips would help greatly. 任何提示都会有很大帮助。 Thanks 谢谢

I finally came to the following solution: 我终于找到了以下解决方案:

I am using Namecheap for the DNS and Amazon S3 bucket with static hosting enabled... 我正在使用Namecheap来启用静态托管的DNS和Amazon S3存储桶...

The solution enables both the ability to access the root domain and the www domain. 该解决方案支持访问根域和www域的能力。 In the namecheap advanced dns configuration I have the following settings: 在namecheap高级DNS配置中,我有以下设置:

CNAME Record    @    domain.com.s3-website-us-west-1.amazonaws.com.
CNAME Record   www   www.domain.com.s3-website-us-west-1.amazonaws.com.

In the Amazon S3 configuration I have two separate buckets created. 在Amazon S3配置中,我创建了两个单独的存储桶。

[S3 Bucket #1] 
Bucket name: www.domain.com
Static website hosting set to:
"Enable website hosting"

[S3 Bucket #2]
Bucket name: domain.com
Static website hosting set to: 
"Redirect all requests to another host name" pointing to www.domain.com (Bucket #1)

With this configuration any of my web traffic coming in on the root domain can hit the Amazon S3 bucket container 'domain.com' and then auto redirect via Amazon to the primary S3 bucket 'www.domain.com' that serves all of my static content. 使用此配置,在根域中进入的任何网络流量都可以访问Amazon S3存储桶容器“domain.com”,然后通过Amazon自动重定向到主要的S3存储桶“www.domain.com”,该存储库提供所有静态服务内容。

If someone attempts to connect directly on the www domain it will go directly to the Amazon S3 container 'www.domain.com' and not need to be redirected thru the 'domain.com' bucket. 如果有人试图直接在www域上连接,它将直接进入Amazon S3容器“www.domain.com”,而不需要通过“domain.com”存储桶重定向。

Hopefully this will help anyone who is running into issues with making your root domain traffic route correctly. 希望这将有助于任何正在解决问题的人正确制定根域流量路由。

So I used jremi's answer but as mentioned below had issues with email being delivered. 所以我使用了jremi的答案,但如下所述,电子邮件的发送存在问题。 After some time with NameCheap support, I have a working solution. 经过一段时间的NameCheap支持,我有一个有效的解决方案。

NameCheap setup NameCheap设置

CNAME Record          www   domain.com.s3-website-us-west-1.amazonaws.com.
URL Redirect Record   @     www.domain.com  (unmasked)

S3 setup (only need 1 bucket) S3设置(只需要1个桶)

[S3 Bucket] 
Bucket name: www.domain.com     <---- This must match your domain exactly
Static website hosting set to:
"Enable website hosting"

S3 bucket Policy S3存储桶策略

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::www.domain.com/*"
        }
    ]
}

This has allowed both domain.com and www.domain.com to work and my NameCheap email works as well. 这允许domain.com和www.domain.com都可以工作,我的NameCheap电子邮件也可以工作。

I used sirclesam's method above and it got me 95% of the way there but my site still wouldn't load until I went and changed some configurations in my AWS S3 console. 我上面使用了sirclesam的方法,它让我有95%的路在那里,但我的网站仍然无法加载,直到我去改变我的AWS S3控制台中的一些配置。

Here are the steps to take: 以下是要采取的步骤:

  1. navigate to S3 dashboard 导航到S3仪表板
  2. click on the bucket you want to use (www.domain.com) 点击你想要使用的水桶(www.domain.com)
  3. click on the 'permissions' nav bar tab 单击“权限”导航栏选项卡
  4. a box should appear with two columns and an 'edit' button in the top right corner of the box - click that edit button 一个框应该出现两列,并在框的右上角有一个“编辑”按钮 - 单击该编辑按钮
  5. there should be 4 total checkboxes - UNCHECK the bottom TWO 应该有4个总复选框 - UNCHECK底部的两个
  6. save and then try to access your site 保存然后尝试访问您的网站

This worked for me. 这对我有用。 I had initially followed a guide which only indicated that one (the third) checkbox needed to be checked but that resulted in my bucket still blocking access so unchecking the last checkbox was what fixed the issue. 我最初遵循的指南只指出需要检查一个(第三个)复选框,但这导致我的存储桶仍然阻止访问,因此取消选中最后一个复选框是解决问题的原因。

For further clarification, the first checkbox (which should be UNCHECKED) reads: "Block public access to buckets and objects granted through new public bucket policies" and the second checkbox (which should ALSO be UNCHECKED)reads: "Block public and cross-account access to buckets and objects through any public bucket policies" 为了进一步说明,第一个复选框(应该是UNCHECKED)读取:“阻止对通过新的公共存储桶策略授予的存储桶和对象的公共访问”,第二个复选框(也应该是UNCHECKED)读取:“阻止公共和跨帐户通过任何公共存储桶策略访问存储桶和对象“

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

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