AWS 控制台中的 CORS 配置不起作用

Chr*_*ris 2 javascript ajax amazon-s3 amazon-web-services cors

我有一些 JavaScript 试图向托管在 AWS 上的服务器上的 RSS 提要发出 ajax 请求,但在发出请求时收到以下错误消息:

XMLHttpRequest cannot load http://www.domain.com/feed. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxx.compute.amazonaws.com' is therefore not allowed access.

我检查了请求标头,Origin标头在那里。

然后,我为 ajax 请求发送到的 AWS 存储桶更新了服务器上的 CORS 配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>http://xxx.compute.amazonaws.com</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)

我还尝试了上述几种不同的变体,但它们似乎都没有什么不同,我的浏览器仍然给出相同的 CORS 错误消息。当我安装 Chrome 扩展程序以禁用 CORS 保护时,代码运行良好,因此似乎只是 CORS 问题阻止了它的工作。

有谁知道为什么 AWS 中存储桶的 CORS 配置不起作用,或者为什么配置可能是错误的?

我已经尝试了几天,但我找到的所有答案都是人们没有意识到您需要允许外部域的跨域共享,或者有关如何在 AWS 上配置 CORS 的基本教程,但我完全遵循这些并且它似乎没有什么区别。

jpr*_*nce 5

通过将以下内容添加到存储桶的 CORS 配置中,我能够解决此错误:

<AllowedMethod>HEAD</AllowedMethod>
Run Code Online (Sandbox Code Playgroud)

完整配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>https://my-subdomain.my-domain.com</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)