【发布时间】:2022-01-08 12:45:54
【问题描述】:
我正在使用 AWS CDK 构建一个 Angular 应用程序。这是为了我的工作,InfoSec 不赞成公开访问的 S3 存储桶。我想使用新的Distribution API 而不为网站托管配置 S3 存储桶。在这种情况下,“存储桶将作为存储桶来源处理,并将使用 CloudFront 的重定向和错误处理”。当我使用以下代码设置分发时,应用程序的根目录工作(即/index.html)但身份验证重定向(/login/callback)会产生“拒绝访问”XML 响应。如何告诉 CloudFront 将所有内容重定向到 index.html?
const bucket = new Bucket(this, "WebUIBucket", {
versioned: false,
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
})
new BucketDeployment(this, "DeployWebUI", {
sources: [Source.asset(path.resolve(__dirname, "../../frontend/dist/myapp"))],
destinationBucket: bucket,
})
const cloudFront = new Distribution(this, "CloudFront", {
defaultBehavior: {
origin: new S3Origin(bucket),
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
},
domainNames: [this.frontendFQDN],
certificate: this.certificate,
priceClass: PriceClass.PRICE_CLASS_100,
defaultRootObject: "index.html",
}
const zone = HostedZone.fromLookup(this, 'Zone', { domainName: 'my.tld' })
new ARecord(this, "frontendDNS", {
zone: this.zone,
recordName: 'my-angular-app',
target: RecordTarget.fromAlias(new CloudFrontTarget(cloudFront)),
}
【问题讨论】:
标签: angular amazon-web-services amazon-s3 amazon-cloudfront aws-cdk