如何修复“从原点'...'对'...'字体的访问已被CORS政策阻止:否'Access-Control-Allow-Origin'

时间:2019-04-13 14:18:32

标签: php html server cors apache2

我尝试配置自己的CDN,但是在加载字体时遇到了问题...每次加载显示为

的网页时
Access to font at 'https://cdn.example.org/css/webfonts/fa-solid-900.ttf' from origin 'https://example.org' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
GET https://cdn.example.org/css/webfonts/fa-solid-900.ttf net::ERR_FAILED

我试图以此更改.htaccess

    <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
    </FilesMatch>

并且我试图更改website.conf

具有:

<VirtualHost cdn.example.org:443>
        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/cdn.example.org/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/cdn.example.org/privkey.pem

        ServerAdmin mail@example.org
        ServerName cdn.example.org
        DocumentRoot /var/www/cdn/
        ErrorLog /var/log/apache2/error.log
<directory "/var/www/cdn/">
        Header set Access-Control-Allow-Origin "*"
        Options Indexes FollowSymLinks
        AllowOverride All
</Directory>
</VirtualHost>

<VirtualHost cdn.example.org:80>
        ServerAdmin mail@example.org
        ServerName cdn.example.org
        DocumentRoot /var/www/cdn/
        ErrorLog /var/log/apache2/error.log
<directory "/var/www/cdn/">
        Header set Access-Control-Allow-Origin "*"
        Options Indexes FollowSymLinks
        AllowOverride All
</Directory>
</VirtualHost>

CSS和js文件可以正常工作,所以我不知道为什么服务器不加载字体...

有人知道我该如何解决吗?

0 个答案:

没有答案