Reputation: 4632
I’m using AWS S3 with CloudFront to host static websites in nested subfolders of buckets. As an example, I have a bucket set up for my-domain.com
with subfolders like /path/to/site/
which have an index.html
file in it. In the settings for the bucket for my-domain.com
, static website hosting is enabled
, the hosting type is Host a static website
and both the Index document and Error document are set to index.html
.
When I load up my-domain.com/path/to/site/index.html
, I get the expected rendered index page. But, if I go to my-domain.com/path/to/site
or my-domain.com/path/to/site/
I get the default AWS NoSuchKey error message.
I’m following the AWS documentation here so I think I’ve got everything set up correctly so I’m stuck as to why it’s not working. What am I missing?
Upvotes: 3
Views: 2960
Reputation: 741
For general reference, it's not possible to specify a Default Root Object for subdirectories in CloudFront. From AWS CF Docs:
However, if you define a default root object, an end-user request for a subdirectory of your distribution does not return the default root object. For example, suppose index.html is your default root object and that CloudFront receives an end-user request for the install directory under your CloudFront distribution:
http://d111111abcdef8.cloudfront.net/install/
CloudFront does not return the default root object even if a copy of index.html appears in the install directory.
Youcan do that via S3, and I understand you're trying to do that, as correctly explained here.
I had a similar situation recently and it was because the file index.html was not set to public access. So, when you upload the file to S3, in the S3 console, select the file then go to Actions -> Make Public. You need to do that even if your bucket has static web hosting enabled. Basically, everytime you upload a file manually.
If you plan to do that programmatically, or via AWS-cli, you can set a flag to make them public accessible (Read permission to everyone).
Upvotes: 1