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

僤鯓⒐⒋嵵緔 提交于 2020-05-09 17:50:06

问题


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

If I enter FOO.com/MyDirectory without the www it will fail.

What is the proper method to make url requests without the www route correctly to the same Amazon S3 bucket?

Any tips would help greatly. Thanks


回答1:


I finally came to the following solution:

I am using Namecheap for the DNS and Amazon S3 bucket with static hosting enabled...

The solution enables both the ability to access the root domain and the www domain. In the namecheap advanced dns configuration I have the following settings:

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.

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

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.

Hopefully this will help anyone who is running into issues with making your root domain traffic route correctly.




回答2:


So I used jremi's answer but as mentioned below had issues with email being delivered. After some time with NameCheap support, I have a working solution.

NameCheap setup

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 Bucket] 
Bucket name: www.domain.com     <---- This must match your domain exactly
Static website hosting set to:
"Enable website hosting"

S3 bucket Policy

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




回答3:


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.

Here are the steps to take:

  1. navigate to S3 dashboard
  2. click on the bucket you want to use (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
  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"



来源:https://stackoverflow.com/questions/37555416/amazon-s3-static-hosting-with-namecheap-dns-how-to-correctly-route-non-www-pre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!