简体   繁体   English

使用 AWS S3 + CloudFront 部署时反应 SPA 空白页

[英]React SPA blank page when deployed using AWS S3 + CloudFront

I uploaded React Single Page App to AWS S3 served with CloudFront.我将 React Single Page App 上传到使用 CloudFront 服务的 AWS S3。 I have two buckets and two CDN (one public and one private) and restricted viewer access using signed cookies on 'private' CDN.我有两个存储桶和两个 CDN(一个公共和一个私有),并且在“私有”CDN 上使用签名的 cookies 限制查看器访问。 My page loads blank after redirecting from the 'public' bucket/CDN.从“公共”存储桶/CDN 重定向后,我的页面加载为空白。

This is html I see when inspected using Google Chrome:这是 html 我在使用谷歌浏览器检查时看到的:

html响应

And error:和错误:

在此处输入图像描述

Snippet from the request/response headers:来自请求/响应标头的片段: 在此处输入图像描述

I have set two error pages in CloudFront 403/404 to return 200 and index.html response page.我在 CloudFront 403/404 中设置了两个错误页面以返回 200 和 index.html 响应页面。 If I remove 403 or change to respond as 403 all of the page content files return 403. My S3 bucket is set to allow GetObject to CloudFront OAI and so does CloudFront distribution use the same identity.如果我删除 403 或更改为响应为 403,所有页面内容文件都返回 403。我的 S3 存储桶设置为允许 GetObject 到 CloudFront OAI,CloudFront 分配也使用相同的身份。

The page is served using custom domain registered and set up in Route53.该页面使用在 Route53 中注册和设置的自定义域提供服务。 I tried specifying homepage in the package.json file, but I get the same result if I either:我尝试在 package.json 文件中指定主页,但如果我得到相同的结果:

  • add 'homepage' in the package.json file using my custom domain使用我的自定义域在 package.json 文件中添加“主页”
  • use "homepage":'.'使用“主页”:'。'
  • Don't specify homepage不指定主页

I've searched every solution out there but nothing seems to work.我已经搜索了所有解决方案,但似乎没有任何效果。

UPDATE: If I turn off 'Restrict viewer access' on the private CDN, my page loads fine (picking up cookies set by the 'public' cdn).更新:如果我关闭私有 CDN 上的“限制查看器访问”,我的页面加载正常(获取由“公共”cdn 设置的 cookies)。

在此处输入图像描述

Your web app is a SPA application, but access to the js file on clouldfront is restricted, so the application crashes.您的 web 应用程序是 SPA 应用程序,但对 couldfront 上的 js 文件的访问受到限制,因此应用程序崩溃。

You need to set up a separate error pages.你需要设置一个单独的错误页面。 eg 403.html .例如403.html And configure in the console.并在控制台中配置。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 S3 CloudFront React SPA由于标签而返回403,但无法设置403错误页面 - S3 CloudFront React SPA returns 403 due to hashtag but cannot setup 403 error page 当从浏览器输入 url 时,AWS 托管(s3,cloudfront)static 反应网站不会路由到子页面 - AWS hosted (s3, cloudfront) static react website does not route to sub page when the url entered from browser 将 brotli 与 AWS Cloudfront + S3 一起使用 - Using brotli with AWS Cloudfront + S3 刷新页面时在 S3 AWS 上反应应用程序 SPA 显示 404 页面 - React app SPA on S3 AWS while refreshing the page shows 404 page 使用 github 页面部署时 React App Blank 的第一页 - First Page of React App Blank when deployed using github pages 在 AWS S3 和 CloudFront 中托管 React 路由器应用程序时出现 403 Access Denied 错误 - Getting 403 Access Denied Errors When Hosting a React Router App in AWS S3 and CloudFront 使用 aws s3 和 cloudfront 托管 React 应用程序。任何人都可以建议配置以访问动态 url 吗? - Using aws s3 and cloudfront to host React application.Can anyone suggest configuration to access dynamic urls? 使用 React 将文件上传到 AWS S3 时使用进度处理程序 - Using progress handler when uploading files to AWS S3 with React 使用React Route部署到S3后查看空白页面 - Seeing empty page after deployed to S3 with React Route AWS Cloudfront S3非常慢 - AWS cloudfront s3 is very slow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM