刷新页面时Cloudfront返回403禁止 [英] Cloudfront returns 403 forbidden when refreshing page

查看:207
本文介绍了刷新页面时Cloudfront返回403禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将React应用程序上传到AWS S3,并且正在使用静态网站托管。然后,我将一个Cloudfront发行版链接到s3存储桶。

I have uploaded a react app to AWS S3 and am using static website hosting. I then linked a cloudfront distribution to the s3 bucket.

除了能够导航到新页面my-domain / new-page之外,我能够导航至该网站并且其功能正常。最初,它成功,但是如果我尝试直接加载页面或刷新,则会收到403禁止的错误。

I am able to navigate to the site and it functions properly except when I navigate to a new page my-domain/new-page. At first it succeeds but if I try and load the page directly or refresh I get a 403 forbidden error.

推荐答案

使用react with S3和CloudFront,我遇到了这个问题或类似的问题,即加载初始索引页面然后链接到其他页面也很好(推送状态更改),但是如果刷新页面或直接链接到页面,则显示为访问被拒绝,状态403。

Using react with S3 and CloudFront, I had this or a similar issue where loading the initial index page and then linking to other pages worked just fine (push state changes), but if I refreshed the page or linked directly to the page, it came up as "Access Denied," status 403.

我找到的解决方案是将403和404错误的自定义错误页面添加到CloudFront配置中。

The solution I found was to add custom error pages for 403 and 404 errors to the CloudFront configuration.

当客户端路由中的页面不存在对象时,S3响应403。

这篇关于刷新页面时Cloudfront返回403禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆