CloudFront已被CORS政策阻止

时间:2020-09-21 11:37:00

标签: amazon-web-services amazon-s3 cors amazon-cloudfront

我使用axios从我的CDN(由AWS CloudFront提供)中获取资源(md文件)。

我在浏览器中收到此错误消息:

通过'https://next.cdn.example.com/foo/bar.md'访问XMLHttpRequest 来源“ https://next.example.com”已被CORS阻止 策略:对预检请求的响应未通过访问控制 检查:标题上没有“ Access-Control-Allow-Origin”标头 请求的资源

My website is: https://next.example.com
My cdn: https://next.cdn.example.com

但是在CloudFront中,我设置了所有功能以支持CORS(如图所示)。

我还能怎么解决这个问题?

S3 enter image description here

enter image description here

CloudFront

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

我相信您需要在CloudFront的行为设置上也允许OPTIONS请求。 OPTIONS请求在CORS请求的实际GET / POST请求之前发送,有关更多详细信息,请参见https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Functional_overview