当它在文件夹中时,无法从 S3 存储桶访问 index.html [英] Can not access index.html from S3 bucket when it's in a folder

查看:19
本文介绍了当它在文件夹中时,无法从 S3 存储桶访问 index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 mywebsite.com(非真实姓名)的 S3 存储桶.在存储桶中,我有一个网站的静态内容,位于名为 build 的文件夹中.

I have an S3 bucket called mywebsite.com(not real name). In the bucket, I have the static contents of a website, in a folder called build.

build文件夹的内容ls build/:

asset-manifest.json     index.html              manifest.json           static
favicon.ico             lu1.png                 service-worker.js

我公开了存储桶:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mywebsite.com/*"
        }
    ]
}

所以我应该可以从这里访问存储桶:

So I should be able to access the bucket from here:

http://mywebsite.com.s3-website.eu-west-2.amazonaws.com(非真实网址)

然后,对于Index documentError document,我尝试指定:

Then, for the Index document and Error document I tried specifying this:

build/index.html

但是,如果我尝试这样做,我会得到:

However, if I try that, I get:

The IndexDocument Suffix is not well formed

所以我只是将Index documentError document 保留为index.html.

So I just left the Index document and Error document to be index.html.

但是现在找不到索引文件了:

But now it can't find the index file:

404 Not Found
Code: NoSuchKey
Message: The specified key does not exist.
Key: index.html

我尝试了来自这里的建议,​​此处此处 但错误仍然存​​在.

I tried the suggestions from here, here and here but the error persists.

这似乎是一个非常普遍的问题.那么您是如何做到让 S3 在文件夹中看到您的 index.html 的?

This seems to be a very common issue. So how did you do such that S3 manages to see your index.html when it's in a folder?

推荐答案

索引文档 index.html 在每个文件夹的基础上使用.

The Index Document index.html is used on a per-folder basis.

因此,当您请求 http://mywebsite.com.s3-website.eu-west-2.amazonaws.com/ 时,它将呈现 /index.html.

So when you request http://mywebsite.com.s3-website.eu-west-2.amazonaws.com/ it is going to render /index.html.

如果您请求 http://mywebsite.com.s3-website.eu-west-2.amazonaws.com/build/,它将呈现 /build/index.html.

If you request http://mywebsite.com.s3-website.eu-west-2.amazonaws.com/build/, it will render /build/index.html.

所以如果你想拥有这种行为,每个文件夹都需要它自己的 index.html 文件.您不能有一个用于所有文件夹的 build/index.html.

So each folder needs it's own index.html file if you want to have that behaviour. You cannot have a single build/index.html that is used for all folders.

关于错误文档的附加说明

错误文档总是相对于根呈现.

The error document is always rendered relative to the root.

因此,如果您请求 /some/folder/that/does/not/exist/,它将呈现 /404.html 如果 404.html 已配置为您的错误文档.

So if you requested /some/folder/that/does/not/exist/, it will render /404.html if 404.html was configured as your Error Document.

这篇关于当它在文件夹中时,无法从 S3 存储桶访问 index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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