【发布时间】: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