Setting index document on S3 website with custom domain
Asked Answered
K

1

5

I'm trying to set an index document for my S3 hosted website. I've

  1. Enabled website hosting on the bucket
  2. Set the index document to "index.html"
  3. Uploaded an index.html file
  4. Made the index.html file public.

The index document works when navigating to the root of the bucket using the raw AWS url, but does not work when using a custom domain:

http://static.appgrinders.com.s3-website-us-east-1.amazonaws.com/index.html (works)
http://static.appgrinders.com.s3-website-us-east-1.amazonaws.com (works)
http://static.appgrinders.com/index.html (works)
http://static.appgrinders.com (Access denied - 403 error)

Kallick answered 1/6, 2017 at 0:14 Comment(4)
Did you enabled Static web hosting and define the index.html document there?Phonotypy
@Phonotypy Yes I explain the steps I took aboveKallick
I normally use CloudFront infront of S3 to cache the content at Edge for faster delivery of static assets, which is the recommended approach. Never came across above with it.Phonotypy
For CloudFront in front of S3 apparently the instructions that apply are docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/…Vargo
P
11

Your DNS isn't configured correctly.

You are pointing to one of the REST endpoints (CNAME s3.amazonaws.com), which doesn't support index documents. You need the DNS to point to the web site hosting endpoint, in this case it's CNAME static.appgrinders.com.s3-website.us-east-1.amazonaws.com. This endpoint is visible in the S3 console.

This change will fix your issue.

http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html

The giveaway of the nature of the misconfiguration (before I confirmed in DNS) was the XML error. The web site hosting endpoints don't return XML errors -- they return the same information, but it's wrapped in some simple HTML, instead of XML.

Note, however, that you will still need to use CloudFront if you want your site to be accessible with SSL. Custom domains in S3 require CloudFront's help for SSL support. The web site hosting endpoints, unlike the REST endpoints, don't listen on port 443 at all.

In the CloudFront configuration, you'll need to avoid the same error -- don't select the bucket name from the dropdown list, since this will send requests to the REST endpoint. You'll need to supply the web site endpoint hostname as the origin.

Pfister answered 1/6, 2017 at 2:17 Comment(4)
Beautiful- that did it! Thanks MichaelKallick
Thanks, it works! You have a small error in CNAME URL example though... Instead of ...s3-website-us-east-1... it should be ...s3-website.us-east-1.... Making an edit.Tog
@Tog that wasn't technically an error, because for us-east-1 and several older regions, both forms are now valid, but that has not always been the case. Older regions originally supported only - but now allow either that or ., though the documentation glosses over this. Newer regions only support the . after s3-website, so it's a reasonable edit.Pfister
Indeed, I stand corrected. AWS docs list endpoints for each region separately. I was just caught by surprise when eu-central-1 didn't work and thought I'd fix the answer. Thanks for clearing it up!Tog

© 2022 - 2024 — McMap. All rights reserved.