来自源的字体已被跨源资源共享策略阻止加载 [英] Font from origin has been blocked from loading by Cross-Origin Resource Sharing policy

查看:46
本文介绍了来自源的字体已被跨源资源共享策略阻止加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几个 Chrome 浏览器上收到以下错误,但不是全部.目前不完全确定问题是什么.

I'm receiving the following error on a couple of Chrome browsers but not all. Not sure entirely what the issue is at this point.

来自源https://ABCDEFG.cloudfront.net"的字体已被跨源资源共享策略阻止加载:请求的资源上不存在Access-Control-Allow-Origin"标头.因此不允许访问源https://sub.domain.com".

Font from origin 'https://ABCDEFG.cloudfront.net' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://sub.domain.com' is therefore not allowed access.

我在 S3 上有以下 CORS 配置

I have the following CORS Configuration on S3

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedHeader>*</AllowedHeader>
   <AllowedMethod>GET</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

请求

Remote Address:1.2.3.4:443
Request URL:https://abcdefg.cloudfront.net/folder/path/icons-f10eba064933db447695cf85b06f7df3.woff
Request Method:GET
Status Code:200 OK
Request Headers
Accept:*/*
Accept-Encoding:gzip,deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:abcdefg.cloudfront.net
Origin:https://sub.domain.com
Pragma:no-cache
Referer:https://abcdefg.cloudfront.net/folder/path/icons-e283e9c896b17f5fb5717f7c9f6b05eb.css
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36

来自 Cloudfront/S3 的所有其他请求都正常工作,包括 JS 文件.

All other requests from Cloudfront/S3 work properly, including JS files.

推荐答案

将此规则添加到您的 .htaccess

Header add Access-Control-Allow-Origin "*" 

更好,正如@david thomas 所建议的,您可以使用特定的域值,例如

even better, as suggested by @david thomas, you can use a specific domain value, e.g.

Header add Access-Control-Allow-Origin "your-domain.com"

这篇关于来自源的字体已被跨源资源共享策略阻止加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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