Amazon CloudFront URL问题 [英] Amazon CloudFront URL issue

查看:201
本文介绍了Amazon CloudFront URL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Amazon CloudFront提供我的前端。我的后端在Amazon EC2上运行。

I use Amazon CloudFront to provide my frontend. My backend runs on Amazon EC2.

我为CloutFront分配了自己的域,并设置了 CNAME 条目。在后端,我将新域添加为允许的原始主机。但是现在我收到 crossorigin 错误消息。

I assigned CloutFront a domain of its own and set the CNAME entry. In my backend I added the new domain as allowed origin host. But now I get crossorigin error messages. Why might that be?

推荐答案

请确保您具有以下设置:

Make sure you have following setup:


  1. 使用Origin头直接在EC2上进行卷曲,看看是否收到CORS响应。 (对于OPTIONS请求)

  2. 在CloudFront上允许OPTIONS请求。

  3. 在CloudFront上白名单的原始标头。

  4. CloudFront默认情况下会转发Origin头,但它不会将Origin头考虑到缓存键中,这意味着如果您第一次发出不带Origin头的请求www.example.com/test,CloudFront会缓存它,而下一个请求都带有Origin头,它是从Cache提供服务的,请确保在进行这些更改后清除缓存。

  1. Make a curl directly on EC2 with Origin header and see if you get the CORS response. (For OPTIONs requests to)
  2. OPTIONS requests are allowed on CloudFront.
  3. Origin header Whitelisted on CloudFront.
  4. CloudFront bydefault forwards Origin header but it doesn't consider Origin header into the cache key which means if you first make a request www.example.com/test without Origin header, CloudFront caches it and for the next requests comes with Origin header, it serves it from Cache, make sure you clear the cache after making these changes.

5。检查是否没有得到对于CORS请求的4xx响应(使用Mozilla进行测试)。

5.Check if you're not getting 4xx response for the CORS request (Use Mozilla to test).

这篇关于Amazon CloudFront URL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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