AWS S3重定向不起作用 [英] AWS S3 redirect not working

查看:329
本文介绍了AWS S3重定向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在AWS S3中创建了一个新存储桶.我想在其中托管一些静态文件,但如果它们还不存在,请重定向到我的主服务器.看起来很简单,但是我没有按照指示进行操作.

I've just created a new bucket in AWS S3. I want to host some static files there but if they're not all there, redirect to my main server. Seems simple but I've followed the instructions with no luck.

在存储桶中,我已授予所有人查看权限.

On the bucket I've given everyone view permissions.

我添加了一个存储桶策略:

I've added a bucket policy:

{
    "Version": "2012-10-17",
    "Id": "Policy999999999",
    "Statement": [
        {
            "Sid": "Stmt9999999999",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucket/*"
        }
    ]
}

在静态网站托管上,我已启用它并创建了简单的index.htm和error.htm页面(不是我需要它们,但如果需要的话).然后添加以下重定向规则:

On the Static Website Hosting, I've enabled it and created simple index.htm and error.htm pages (not that I need them but in case it's required). Then added these redirection rules:

<RoutingRules>
    <RoutingRule>
        <Condition>
            <HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals>
        </Condition>
        <Redirect>
            <Protocol>http</Protocol>
            <HostName>www.mydomain.com</HostName>
            <ReplaceKeyPrefixWith>/</ReplaceKeyPrefixWith>
        </Redirect>
    </RoutingRule>
</RoutingRules>

(显然,如果它没有列表权限,则您需要403而不是404,但它不适用于403/404的任何变体,以及是否具有列表权限)

(apparently you need 403 not 404 if it doesn't have list permissions but it doesn't work on any variation of 403/404 and having list permissions on or not)

当我转到不存在的存储桶中的URL(存在的URL就可以了)时,我会得到:

When I go to a URL on the bucket that doesn't exist (ones that exist are fine) I just get:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>9DD57C7132E76D65</RequestId>
<HostId>
I15odykUdMnGCC+hQfb1pfsnt+gkfGVxuD2sy5PrxrX16P8Njpy3yQiLLH30evTkdOOAl28HA9M=
</HostId>
</Error>

(如果启用了列表权限,则为NoSuchKey)

(or NoSuchKey if list permissions are on)

帮助!

推荐答案

在网站托管设置下检查控制台,以找到您的存储桶的网站端点主机名.

Check the console under web site hosting settings to find the web site endpoint hostname for your bucket.

您正在将请求发送到REST端点主机名-如XML错误消息所示.

You are sending requests to the REST endpoint hostname -- as evidenced by the XML error message.

http://docs.aws.amazon.com/AmazonS3/Latest/dev/WebsiteEndpoints.html

此外,您将想要用空字符而不是斜杠替换键前缀,否则您将以两个斜杠结尾.

Also, you'll want to replace the key prefix with nothing, not a slash, or you'll end up with two slashes.

这篇关于AWS S3重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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