Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 当索引.html位于文件夹中时,无法从S3 bucket访问它_Amazon Web Services_Amazon S3 - Fatal编程技术网

Amazon web services 当索引.html位于文件夹中时,无法从S3 bucket访问它

Amazon web services 当索引.html位于文件夹中时,无法从S3 bucket访问它,amazon-web-services,amazon-s3,Amazon Web Services,Amazon S3,我有一个名为mywebsite.com的S3 bucket,不是真实姓名。在bucket中,我有一个网站的静态内容,在一个名为build的文件夹中 生成文件夹ls build/的内容: 我公开了这个桶: { "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Pr

我有一个名为mywebsite.com的S3 bucket,不是真实姓名。在bucket中,我有一个网站的静态内容,在一个名为build的文件夹中

生成文件夹ls build/的内容:

我公开了这个桶:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mywebsite.com/*"
        }
    ]
}
因此,我应该能够从这里访问桶:

非真实url

然后,对于索引文档和错误文档,我尝试指定以下内容:

build/index.html

<RoutingRules>
  <RoutingRule>
   <Condition>
     <KeyPrefixEquals> 
       index.html
     </KeyPrefixEquals>
    </Condition>
  <Redirect>
     <ReplaceKeyPrefixWith>build/index.html</ReplaceKeyPrefixWith></Redirect>
  </RoutingRule>
</RoutingRules>
但是,如果我尝试这样做,我会得到:

The IndexDocument Suffix is not well formed
因此,我将索引文档和错误文档保留为Index.html

但现在它找不到索引文件:

404 Not Found
Code: NoSuchKey
Message: The specified key does not exist.
Key: index.html
我尝试了来自的建议,但错误仍然存在

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

索引文档index.html是按文件夹使用的

所以当你要求http://mywebsite.com.s3-website.eu-west-2.amazonaws.com/ 它将呈现/index.html

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

因此,每个文件夹都需要它自己的index.html文件,如果您希望这样做的话。不能将单个build/index.html用于所有文件夹

关于错误文档的附加说明

错误文档始终相对于根呈现

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

索引文档Index.html是按文件夹使用的

所以当你要求http://mywebsite.com.s3-website.eu-west-2.amazonaws.com/ 它将呈现/index.html

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

因此,每个文件夹都需要它自己的index.html文件,如果您希望这样做的话。不能将单个build/index.html用于所有文件夹

关于错误文档的附加说明

错误文档始终相对于根呈现

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

编辑 经过一些广泛的测试。我认为前面的规则不适用于/root路径,并创建了一个连续重定向,然后我提出了这个规则,它适用于我

需要自定义重定向规则将/index.html重定向到/build/index.html

<RoutingRules>
  <RoutingRule>
   <Condition>
     <KeyPrefixEquals> 
       index.html
     </KeyPrefixEquals>
    </Condition>
  <Redirect>
     <ReplaceKeyPrefixWith>build/index.html</ReplaceKeyPrefixWith></Redirect>
  </RoutingRule>
</RoutingRules>
参考:编辑 经过一些广泛的测试。我认为前面的规则不适用于/root路径,并创建了一个连续重定向,然后我提出了这个规则,它适用于我

需要自定义重定向规则将/index.html重定向到/build/index.html

<RoutingRules>
  <RoutingRule>
   <Condition>
     <KeyPrefixEquals> 
       index.html
     </KeyPrefixEquals>
    </Condition>
  <Redirect>
     <ReplaceKeyPrefixWith>build/index.html</ReplaceKeyPrefixWith></Redirect>
  </RoutingRule>
</RoutingRules>
参考: