Redirect to index.html for S3 subfolder

前端 未结 6 737
庸人自扰
庸人自扰 2020-12-25 12:37

I have a domain example.com. I have a S3 bucket named example.com setup with an index.html file that works. Now I like to create two s

6条回答
  •  温柔的废话
    2020-12-25 12:54

    If you are using CDK to create a CloudFrontWebDistribution with an S3 source, then your first guess is probably to do this:

                    OriginConfigs = new[] {
                        new SourceConfiguration {
                            S3OriginSource = new S3OriginConfig
                            {
                                S3BucketSource = bucket
                            }
                            Behaviors = new[] { new Behavior { IsDefaultBehavior = true } }
                        }
                    }
    

    However, to configure cloudfront to use the website-bucket-url (that does have the behavior to resolve a directory to index.html), you need to use:

                    OriginConfigs = new[] {
                        new SourceConfiguration {
                            CustomOriginSource = new CustomOriginConfig
                            {
                                DomainName = bucket.BucketWebsiteDomainName,
                                OriginProtocolPolicy = OriginProtocolPolicy.HTTP_ONLY
                            },
                            Behaviors = new[] { new Behavior { IsDefaultBehavior = true } }
                        }
                    }
    

    You need to specify the protocol as HTTP_ONLY because website buckets do not support HTTPS. The default for a CustomOriginSource is HTTPS_ONLY.

提交回复
热议问题