我有一个使用font-awesome的网站,我想用cloudfront作为CDN(我的网站运行在apache上)。 我已经在这个网站的conf文件中启用了cors。
这里是我的网站的conf文件:
<VirtualHost *:80> ServerAdmin [email protected] ServerName spotlessmommy.com ServerAlias www.spotlessmommy.com DocumentRoot /var/www/spotlessmommy <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/spotlessmommy> Options Indexes FollowSymLinks MultiViews AllowOverride ALL Order allow,deny allow from all Header set Access-Control-Max-Age "1000" Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding" Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT" <FilesMatch ".(eot|ttf|otf|woff)"> Header set Access-Control-Allow-Origin "*" </FilesMatch> </Directory>
我得到正确的头通过时,我试着用curl –
E:\Software Files\curl>curl -I spotlessmommy.com/wp-content/themes/sociallyviral /fonts/fontawesome-webfont.ttf HTTP/1.1 200 OK Date: Tue, 08 Sep 2015 01:04:00 GMT Server: Apache/2.4.7 (Ubuntu) Last-Modified: Fri, 29 May 2015 19:46:10 GMT ETag: "228fc-5173dba530480" Accept-Ranges: bytes Content-Length: 141564 Access-Control-Max-Age: 1000 Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorizat ion, Accept, Client-Security-Token, Accept-Encoding Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT Vary: User-Agent Access-Control-Allow-Origin: * E:\Software Files\curl>curl -I spotlessmommy.com HTTP/1.1 200 OK Date: Tue, 08 Sep 2015 01:04:03 GMT Server: Apache/2.4.7 (Ubuntu) X-Powered-By: PHP/5.5.9-1ubuntu4.11 X-Pingback: http://spotlessmommy.com/xmlrpc.php Access-Control-Max-Age: 1000 Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorizat ion, Accept, Client-Security-Token, Accept-Encoding Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT Vary: User-Agent Content-Type: text/html; charset=UTF-8
但在浏览器中,我仍然得到字体文件的交叉错误。 该网站是www.spotlessmommy.com(如果您加载该网站,您可以看到社交媒体图标只是空的框)
Font from origin 'http://d13wghwkc7ps4m.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://spotlessmommy.com' is therefore not allowed access.
任何想法,我还应该尝试什么? 过去14小时一直在努力挣扎:(
没关系。 这是由于CDNcaching的延迟。 24小时后,现在可以find。