【问题标题】:Amazon S3 + Cloudfront React app fully working but with 404 errorAmazon S3 + Cloudfront React 应用程序完全运行但出现 404 错误
【发布时间】:2020-10-09 13:28:36
【问题描述】:

我有一个部署到 Amazon S3 并由 Cloudfront 分发的 React 应用程序,它现在完全可以按预期工作。 但是,当我打开浏览器控制台时,它会显示 404 错误。

例如,假设我的网站地址是https://shinhong.com

  • 在地址栏中输入https://shinhong.com并回车:正常工作
  • 现在点击网站上的一些链接并导航到https://shinhong.com/path/to/something正常工作
  • 现在刷新当前页面 (https://shinhong.com/path/to/something):有效,但显示 404 错误,如 GET https://shinhong.com/path/to/something 404 (Not Found)
  • 或在地址栏中输入https://shinhong.com/path/to/something并回车:有效,但显示与上述相同的错误

404 错误的网络请求具有以下响应标头:

x-amz-cf-pop: ICN51-C1
x-amz-error-code: NoSuchKey
x-amz-error-detail-key: admin/logs
x-amz-error-message: The specified key does not exist.
x-cache: Error from cloudfront

但有回应:

<!doctype html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8"/>
        <link rel="shortcut icon" href="/favicon.ico"/>
        <meta name="viewport" content="width=device-width,initial-scale=1"/>
        <meta name="theme-color" content="#2c7be5"/>
        <link rel="manifest" href="/manifest.json"/>
...

这是普通的public/index.html 文件。

我已经检查了这个链接CloudFront + S3 Website: "The specified key does not exist" when an implicit index document should be displayed,但没有运气。

另外,当我通过 Cloudfront 域 https://dq9*****u4da.cloudfront.net 或 S3 存储桶域 mys3bucket.s3-website.ap-northeast-2.amazonaws.com 访问时,一切都是一样的。顺便说一句,我的开发服务器没有错误。

你能提出这个奇怪问题的任何可能原因吗?

谢谢。

【问题讨论】:

  • 似乎工作正常,没有出现 404。分享 404 页面截图
  • @muasif80 感谢您的评论。这似乎是一个临时错误。现在已经解决并且运行良好。

标签: reactjs amazon-s3 amazon-cloudfront


【解决方案1】:

我有相同的配置:Amazon S3 + Cloudfront React 应用程序 我想我在 Cloudfront 中解决了它

我将 HTTP Responde Code 从 400 更改为 200

现在如果我去https://example.com/signup,我就没有400了

【讨论】:

  • 它现在对我有用。但这不是正确的做法。这是一种解决方法。 Lambda@Edge 或 S3 存储桶重定向可能是一个很好的解决方案,但它暂时无法使其正常工作。如果有人有更好的知识,请提供。谢谢
猜你喜欢
  • 2017-06-20
  • 1970-01-01
  • 1970-01-01
  • 2022-09-29
  • 2022-01-06
  • 1970-01-01
  • 2021-05-03
  • 2020-06-25
  • 2019-04-20
相关资源
最近更新 更多