0
Access to font at '/fonts/fontawesome-webfont.woff?v=4.7.0' from origin 'https://www.origin.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Magento 2 https://www.origin.com, we created CloudFront for static and for media files. I get this error for all fonts woff,woff2 and ttf and also js-translation.json.

My ngnix settings:

location / {
try_files $uri $uri/ /index.php$is_args$args;
    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
    add_header Access-Control-Allow-Origin * always;
    }
    location ~* \.(eot|ttf|woff|woff2)$ {
    add_header Access-Control-Allow-Origin * always;
}
}
location /pub/ {
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
    deny all;
}
location ~* \.(eot|ttf|woff|woff2)$ {
    add_header Access-Control-Allow-Origin * always;
}
alias $MAGE_ROOT/pub/;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Frame-Options-2 "SAMEORIGIN-2";
}

I also updated setting on CloudFront from here https://aws.amazon.com/premiumsupport/knowledge-center/no-access-control-allow-origin-error/

Also tried NGINX cross control origin header added but font files still blocked by CORS policy

Nothing helps. Please advise

0

This answer is simple. Goto Apache or Nginx and add my detailed example to MIME/TYPE: application/eot|ttf|woff|woff2 and so on. Save and restart Apache. Should be fine. This will clear that CORS. Just to mention that you are using add_header X-Frame-Options "SAMEORIGIN"; add_header X-Frame-Options-2 "SAMEORIGIN-2"; Try defined option like so add_header X-Frame-Options "Samesite="None"; add_header X-Frame-Options-2 "SAMEORIGIN-2"; use Samesite="None" since you want public users to access your resource. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.