使用AWS CDK设置CloudFrontWebDistribution以从S3存储桶获取GET / subdirectory服务器/subdirectory/index.html

我正在使用https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/static-site AWS cdk示例来配置Cloudfront + S3存储桶以为静态站点提供服务。

虽然看起来对GET / subdirectory的请求不会以/subdirectory/index.html进行响应。一个人将如何使用cdk将Cloudfront + S3配置为服务/subdirectory/index.html?

yin088 回答:使用AWS CDK设置CloudFrontWebDistribution以从S3存储桶获取GET / subdirectory服务器/subdirectory/index.html

如果您不想使用 lambda,您可以将错误重定向到 index.html,这是您应该使用

在 CloudFront 上托管 SPA 的方式
errorConfigurations: [
       {
          errorCode: 403,responseCode: 200,responsePagePath: '/index.html',errorCachingMinTtl: 10
       }
   ]

有关详细信息,请参阅 https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CfnDistribution.CustomErrorResponseProperty.html

,

最后我找到了创建Lambda @ Edge函数的解决方案,该函数执行了Url Rewrite。

https://briantakita.com/posts/static-https-websites-using-aws-cdk-cloudfront-and-s3

源代码包含在此gist中。

本文链接:https://www.f2er.com/3141710.html

大家都在问