为什么使用AWS CloudFront会出现CORS客户端错误?

时间:2020-09-22 04:21:51

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

我在使用Cloudfront(签名的cookie)提供私人文件时遇到问题。

对于邮递员来说,它可以工作,但是,如果我尝试显示HTML图像(在显示之前设置了cookie),则会发生以下情况:

  1. 如果我在图像标签中添加crossOrigin =“ use-credentials”,则会收到CORS错误“已被CORS策略阻止:请求中没有'Access-Control-Allow-Origin'标头资源。”

  2. 如果不添加交叉原点,则会出现403错误。

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>HEAD</AllowedMethod>
     <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

我在cloudfront发行版中只有1种行为,这就是我的行为: enter image description here

最后这就是我生成Cookie的方式(服务器端) enter image description here

1 个答案:

答案 0 :(得分:0)

尝试在“允许的HTTP方法”上激活,以仅激活GET, HEAD, OPTIONS的{​​{1}}。