gpt4 book ai didi

amazon-web-services - 如何修复 nextjs cloudfront 静态 Assets 响应 403?

转载 作者:行者123 更新时间:2023-12-04 04:17:34 26 4
gpt4 key购买 nike

我正在尝试使用 cloudfront 和 route53 将我的网站部署到 aws。该站点已在 https://higgle.io 上部署和运行
但是 Assets 没有加载,因为图像抛出 403。我该如何解决?
我正在使用无服务器 serverless-next.js .我正在关注他们的一篇博客文章进行设置。
到目前为止,我添加了 serverless.yml在路线层面。

higgle:
component: serverless-next.js

我的 next.config.js 看起来像
module.exports = {
target: 'serverless',
webpack: (config) => {
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
return config
}
}

虽然文件夹结构看起来像
-root
-.next
-pages
-_document.js
-index.js
-public
-static
-favicon.ico
-next.config.js
-package.json
-serverless.yml

知道如何解决这个问题吗?
谢谢

最佳答案

S3 返回 403,因为您的项目是私有(private)的。

  • 将您的 S3 项目更改为公开。检查它们是否可以通过您的 S3 静态托管地址访问。
  • 第 1 步将修复所有静态资源。如果您正在运行单页应用程序,您还需要在 S3 返回 404 时返回您的索引页。在 CloudFront 中,转到错误页面,创建自定义错误响应,选择 404 响应,选择自定义响应选项,将响应代码 200 和响应页面路径设为您的索引页面。

  • 您的存储桶策略应该是:
    {
    "Version": "2012-10-17",
    "Id": "Policy1517754859350",
    "Statement": [
    {
    "Sid": "Stmt1517754856505",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"
    }
    ]

    }

    关于amazon-web-services - 如何修复 nextjs cloudfront 静态 Assets 响应 403?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60314382/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com