Facebook在其 Canvas 设置文档中指出:



使用以下CORS配置,我的应用程序作为静态网站托管在AWS S3上:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

我已经在这里遇到问题了。 GET请求可以正常工作,但是http://my-bucket-name.s3-website-us-east-1.amazonaws.comPOST会反跳:
<html>
    <head>
        <title>405 Method Not Allowed</title>
    </head>
    <body>
        <h1>405 Method Not Allowed</h1>
        <ul>
            <li>Code: MethodNotAllowed</li>
            <li>Message: The specified method is not allowed against this resource.</li>
            <li>Method: POST</li>
            <li>ResourceType: OBJECT</li>
            <li>RequestId: 94159551A72424C7</li>
            <li>HostId: +Lcz+XaAzL97Y47OZFvaTwqz4Z7r5koaJGHjZJBBMOTUHyThTfKbZG6IxJtYEbtsXWcb/bFxeI8=</li>
        </ul>
        <hr/>
    </body>
</html>

第1步:^我想我需要使此工作正常进行。

,但等等,还有更多

Facebook还需要一个安全网址。所以为此,我去了云端。

我的配置如下所示:

amazon-web-services - 如何配置AWS S3以允许POST像GET一样工作-LMLPHP

amazon-web-services - 如何配置AWS S3以允许POST像GET一样工作-LMLPHP

就像直接使用S3一样,向https://app-cloudfront-id.cloudfront.net/发出GET请求就像冠军,POST一样,可以消除以下问题:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>MethodNotAllowed</Code>
    <Message>The specified method is not allowed against this resource.</Message>
    <Method>POST</Method>
    <ResourceType>OBJECT</ResourceType>
    <RequestId>657E87A80AFBB3B0</RequestId>
    <HostId>SY2g4smvhr06kAAQYVMsYeQZ+pSKbIIvsh/OaPBiMADGt5UKut0sXSZkFsnFmcRXQ2PFBVgPK4M=</HostId>
</Error>

在facebook.com上查看该应用程序显示:

amazon-web-services - 如何配置AWS S3以允许POST像GET一样工作-LMLPHP

我缺少什么吗?

最佳答案

所以-我也认为这应该很容易并且在2016年得到AWS的良好支持。显然,从我所做的所有阅读中,我们错了。

不管有没有Cloudfront,都无法为s3中的Facebook应用程序提供索引页面。

也许可以通过cloudfront和s3的其他源从备用源(即,您自己的httpd在某处运行)提供索引页,但是我没有尝试深入研究这个兔子洞。而且,如果您仍然必须运行自己的HA httpd,那么根据 Assets 规模而定,复杂性可能不值得。即http://www.bucketexplorer.com/documentation/cloudfront--how-to-create-distributions-post-distribution-with-multiple-origin-servers.html

您可以在提供静态内容的原始httpd前面使用cloudfront来利用缓存和边缘分布的优势-它只会将POST(和PUT等)转发到您的原始位置,并绕过缓存边缘。

这些答案很旧,大约在2011年,但是我找不到任何证据证明此事发生了任何变化。

https://forums.aws.amazon.com/thread.jspa?messageID=228988&#228988

https://forums.aws.amazon.com/thread.jspa?threadID=62525

希望我们可以在该线程上进行一些事件来证明我是错误的,我现在也可以使用此功能。

关于amazon-web-services - 如何配置AWS S3以允许POST像GET一样工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36404379/

10-09 01:20
查看更多