Amazon CloudFront URL issue

南楼画角 提交于 2019-12-11 18:00:52

问题


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

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?


回答1:


Make sure you have following setup:

  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.Check if you're not getting 4xx response for the CORS request (Use Mozilla to test).




回答2:


Did you check the CORS support? for exmaple by forwarding the origin header? see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/forward-custom-headers.html

Try calling the URL using

curl -H "origin: example.com" -v "https://examplec.com"

and check the output

see also https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-cors



来源:https://stackoverflow.com/questions/55357846/amazon-cloudfront-url-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!