How do you set a default root object for subdirectories for a statically hosted website on Cloudfront?

前端 未结 9 1981
[愿得一人]
[愿得一人] 2020-12-22 17:33

How do you set a default root object for subdirectories on a statically hosted website on Cloudfront? Specifically, I\'d like www.example.com/subdir/index.html

9条回答
  •  鱼传尺愫
    2020-12-22 18:20

    UPDATE: It looks like I was incorrect! See JBaczuk's answer, which should be the accepted answer on this thread.

    Unfortunately, the answer to both your questions is no.

    1. Is it possible to specify a default root object for all subdirectories for a statically hosted website on Cloudfront?

    No. As stated in the AWS CloudFront docs...

    ... 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 will not return the default root object even if a copy of index.html appears in the install directory.

    ...

    The behavior of CloudFront default root objects is different from the behavior of Amazon S3 index documents. When you configure an Amazon S3 bucket as a website and specify the index document, Amazon S3 returns the index document even if a user requests a subdirectory in the bucket. (A copy of the index document must appear in every subdirectory.)

    2. Is it possible to setup an origin access identity for content served from Cloudfront where the origin is an S3 website endpoint and not an S3 bucket?

    Not directly. Your options for origins with CloudFront are S3 buckets or your own server.

    It's that second option that does open up some interesting possibilities, though. This probably defeats the purpose of what you're trying to do, but you could setup your own server whose sole job is to be a CloudFront origin server.

    When a request comes in for http://d111111abcdef8.cloudfront.net/install/, CloudFront will forward this request to your origin server, asking for /install. You can configure your origin server however you want, including to serve index.html in this case.

    Or you could write a little web app that just takes this call and gets it directly from S3 anyway.

    But I realize that setting up your own server and worrying about scaling it may defeat the purpose of what you're trying to do in the first place.

提交回复
热议问题