Hot to enable CORS policy for font in Linux (nginx) WordPress App Service

Tim Gitchel 0 Reputation points
2023-01-30T19:20:04.9133333+00:00

I see lots of references to fixing CORS errors for fonts in WordPress using Windows App Service (IIS) in web.config. I don't see how to make this work when deployed to Linux App Service (nginx). The nginx.conf file already has the correct settings based on what I can find. How to make this work?

location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css)$ {
    expires 31536000s;
    etag on;
    if_modified_since exact;
    add_header Pragma "public";
    add_header Cache-Control "public";
    add_header Referrer-Policy "no-referrer-when-downgrade";
    add_header Access-Control-Allow-Origin "*";
}
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,913 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,636 Reputation points Microsoft Employee
    2023-02-02T22:05:39.8733333+00:00

    @Tim Gitchel You are right about the CDN not forwarding the CORS headers, which is why the browser is rejecting the requests. If you had enabled CORS after setting up the CDN, then you would have to purge content and it should have worked after that, assuming the origin sent back is either * or the hostname of the CDN.

    While it may not be applicable to your scenario since you just have a wordpress site, for others coming across this issue and require supporting multiple origins, you will have to setup rules to return headers as required. Check this doc for more information.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.