如何修复 AccessDenied 错误 CloudFront Angular 部署的应用程序?

How to fix AccessDenied error CloudFront Angular deployed application?

我正在设置一个部署在 S3 上并由 CloudFront 分发处理的 Angular 应用程序。当我访问该应用程序时,它可以正常工作,但是如果我重新加载页面,则会出现以下错误:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>E716BA4DFD8C1B54</RequestId>
<HostId>
0EcNthjt/zlsAZxEx8JncShstTBNxFram3F6Jy2uI0LD+am1l+7YxGAbZ1dVphkuhZj32mnkjug=
</HostId>
</Error>

我已经按照本教程设置了包含所有必需字段的 CloudFront 分配:

Deploy an angular spa as a static website

我已将 index.html 作为默认根对象,并将其放在 S3 存储桶的索引文档选项下。

使用该设置它应该可以工作并在您重新加载页面时使用 angular 的 index.html,但我收到 AccessDenied 错误。

好的伙计们,我刚刚从同一篇文章中发现了问题:

Deploy an angular spa as a static website

值得注意的是:

Important: Origin Domain Name will provide you with the drop down of S3 bucket. You shouldn’t use that. As it omitted the S3’s region and it will cause the request to redirect instead of passing through the traffic through CloudFront. (May be there is a better way to configure this I’m not sure.) So just copy-and-paste your S3 URL here. .s3-.amazonaws.com .

确保将具有以下 URL 结构的存储桶作为源域名放置:

<bucket-name>.s3-website-<bucket-region>.amazonaws.com

不要使用建议的存储桶 URL 结构,因为它不起作用。希望这对以后有帮助。