0

Have a Magento 2.3 on Nginx. Trying to set up Cloudfront for /pub/static/ on subdomain like https://static.mydomain.com.

Base URL for Static View Files is https://static.mydomain.com. Getting error for all files .woff:

Access to font at has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Get net::ERR_FAILED

Ngnix magento settings for /static/

location /static/ {
location ~ ^/static/version {
    rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
    etag on;
    if_modified_since exact;
    add_header Pragma "public";
    add_header Cache-Control "max-age=31536000, public";
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,Authorization,X-CustomHeader,Keep-Alive,User-Agent,Origin,Referer,X-HTTP-Method-Override,X-Accept-Charset,X-Accept,Accept,Access-Control-Request-Method,Access-Control-Request-Headers,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type' always;
    add_header X-Frame-Options "SAMEORIGIN";
    expires +1y;

    if (!-f $request_filename) {
        rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
    }
}

location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
    add_header Cache-Control "no-store";
    add_header X-Frame-Options "SAMEORIGIN";
    expires    off;

    if (!-f $request_filename) {
       rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
    }
}

if (!-f $request_filename) {
    rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
}

add_header X-Frame-Options "SAMEORIGIN";

}

Still doesnt work. What Am I doing wrong here? Thanks

  • Is this the Cloudfront worker that's claiming a CORS error, or is this when you visit your site the Cloudfront served resources are generating this error? – Brett Jan 15 at 2:18
  • @Brett I see error when I visit my site im not sure how to check what you are asking about – Olga Bautina Jan 15 at 3:32
  • If Magento is configured to use the CDN for its resources (e.g. static.mysite.com) and not Magento itself (e.g. www.mysite.com), then you need to configure Cloudfront correctly to pass the appropriate CORS headers. See the AWS documentation on this exact error: aws.amazon.com/premiumsupport/knowledge-center/… – Brett Jan 15 at 3:48
  • @Brett Still showing error, Im not an expert in Cloudfront but I did everything according to books...here is a website dscbalances.com please take a look, maybe you would have an idea. – Olga Bautina 2 days ago
  • @Brett by the way just noticed that fonts shows on website in Safari but not Chrome – Olga Bautina 2 days ago

Your Answer

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

Browse other questions tagged or ask your own question.