Access-Control-Allow-Origin标题从响应中缺失

我正在尝试debugging一个问题。

在我的一个网站上,字体文件加载不正确。 有人在检查员日志中报告了这个错误:

Font from origin 'http://d1h0r2f9g9fk4d.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 'http://bit.ly/1Z4W4JZ' is therefore not allowed access. 

谁说他看不到字体文件的人也附上了这个网站的截图:

在这里输入图像说明

你可以看到字体(应该是插入不显示)。

在这种情况下,我相信这是不会为他加载的字体。


  • Cloudfront是CDN
  • nGinx是原点(并正确发送Access-Control-Allow-Origin标头)

我已经执行了curl -v -I ,你可以看到这个回应:

我的工作回应

 curl -v -I http://d1h0r2f9g9fk4d.cloudfront.net/static/release/fonts/fontawesome-webfont.ttf?v=4.3.0 * Hostname was NOT found in DNS cache * Trying 54.230.149.120... * Connected to d1h0r2f9g9fk4d.cloudfront.net (54.230.149.120) port 80 (#0) > HEAD /static/release/fonts/fontawesome-webfont.ttf?v=4.3.0 HTTP/1.1 > User-Agent: curl/7.35.0 > Host: d1h0r2f9g9fk4d.cloudfront.net > Accept: */* > < HTTP/1.1 200 OK HTTP/1.1 200 OK < Content-Type: application/octet-stream Content-Type: application/octet-stream < Connection: keep-alive Connection: keep-alive * Server nginx/1.4.6 (Ubuntu) is not blacklisted < Server: nginx/1.4.6 (Ubuntu) Server: nginx/1.4.6 (Ubuntu) < Date: Wed, 06 Jan 2016 09:33:59 GMT Date: Wed, 06 Jan 2016 09:33:59 GMT < Last-Modified: Tue, 09 Jun 2015 10:46:31 GMT Last-Modified: Tue, 09 Jun 2015 10:46:31 GMT < ETag: "5576c407-1dcec" ETag: "5576c407-1dcec" < Expires: Thu, 04 Feb 2016 18:03:03 GMT Expires: Thu, 04 Feb 2016 18:03:03 GMT < Cache-Control: max-age=2592000 Cache-Control: max-age=2592000 < X-Varnish: 2146103981 2146009331 X-Varnish: 2146103981 2146009331 < Age: 55857 Age: 55857 < Via: 1.1 varnish, 1.1 f836ea1710367746c54dbe5fbb422013.cloudfront.net (CloudFront) Via: 1.1 varnish, 1.1 f836ea1710367746c54dbe5fbb422013.cloudfront.net (CloudFront) < X-Hashed-On: /static/release/fonts/fontawesome-webfont.ttf?v=4.3.0*cdn.rentivo.com X-Hashed-On: /static/release/fonts/fontawesome-webfont.ttf?v=4.3.0*cdn.rentivo.com < X-Discovery: not-set X-Discovery: not-set < X-Cache-Lookup: lookup X-Cache-Lookup: lookup < X-Cachable: 1 X-Cachable: 1 < Access-Control-Allow-Origin: * Access-Control-Allow-Origin: * < X-Cache: Miss from cloudfront X-Cache: Miss from cloudfront < X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q== X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q== < * Connection #0 to host d1h0r2f9g9fk4d.cloudfront.net left intact 

您可以清楚地看到Access-Control-Allow-Origin: *存在于字体标题中。

我试图使Cloudfront发行版无效,可能是边缘服务器有一个旧版本,没有这些头文件,但是这个人仍然说他一直无法查看头文件。

我问他为我做一个curl的日志,这是他的回应。

他的回答失败了

 curl -v -I http://d1h0r2f9g9fk4d.cloudfront.net/static/release/fonts/fontawesome-webfont.ttf?v=4.3.0 * Trying 54.230.149.120... * Connected to d1h0r2f9g9fk4d.cloudfront.net (54.230.149.120) port 80 (#0) > HEAD /static/release/fonts/fontawesome-webfont.ttf?v=4.3.0 HTTP/1.1 > Host: d1h0r2f9g9fk4d.cloudfront.net > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 200 OK HTTP/1.1 200 OK < Content-Encoding: gzip Content-Encoding: gzip < Content-Length: 71646 Content-Length: 71646 < Content-Type: application/octet-stream Content-Type: application/octet-stream < ETag: "5576c407-1dcec" ETag: "5576c407-1dcec" < Server: nginx/1.4.6 (Ubuntu) Server: nginx/1.4.6 (Ubuntu) < Expires: Wed, 03 Feb 2016 10:08:00 GMT Expires: Wed, 03 Feb 2016 10:08:00 GMT < Last-Modified: Tue, 09 Jun 2015 10:46:31 GMT Last-Modified: Tue, 09 Jun 2015 10:46:31 GMT < Connection: keep-alive Connection: keep-alive < Date: Wed, 06 Jan 2016 01:04:10 GMT Date: Wed, 06 Jan 2016 01:04:10 GMT < * Connection #0 to host d1h0r2f9g9fk4d.cloudfront.net left intact 

我不明白发生了什么事。 他的ISP可以对他进行一些荒谬的窥探/优化吗? 如果您注意到,标题响应甚至不匹配。 你至less期望看到

 < X-Cache: Miss from cloudfront X-Cache: Miss from cloudfront < X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q== X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q== 

这些都是缺失的。

有没有人有任何见解?

迟到的反应,但同时也遇到同样的问题,偶然发现这个线程。

尝试添加一个Origin头到你的curl请求; 这固定了我 – 像这样的:

 curl -v -I "http://d1h0r2f9g9fk4d.cloudfront.net/static/release/fonts/fontawesome-webfont.ttf?v=4.3.0" -H "Origin: https://example.com"