Get the App
SLTechnology News&Howtos  ›  Servers  › 

What if the font cannot be displayed when using a subdomain name to access the CSS of the root domain name

Shulou Source: shulou.com Published: 2022-06-01 14:17:46 10月02日 Update

This article mainly introduces "what to do if the font cannot be displayed when accessing the CSS of the root domain using a subdomain name". In the daily operation, it is believed that many people have doubts about how to use the subdomain name to access the CSS of the root domain name when the font cannot be displayed. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful for you to answer the question of "what to do if the font cannot be displayed when accessing the CSS of the root domain using a subdomain name"! Next, please follow the editor to study!

Problem description

Today, when using a subdomain name to access the CSS of the root domain name, it is found that the font cannot be displayed. After ensuring that the path loading of CSS and Font fonts is not a problem, it is basically due to cross-domain problems.

Add the addresses allowed by Access-Control-Allow-Origin through the Nginx module Http_Headers_Module

Console error message

Ccess to Font at 'http://w001.static.akhack.com/css/KohinoorBangla-Regular.ttf' from origin' http://carey.akhack.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://carey.akhack.com' is therefore not allowed access.

Solution method

Location ~ *\. (eot | ttf | woff | svg | otf) ${add_header Access-Control-Allow-Origin http://carey.akhack.com; add_header Access-Control-Allow-Headers XmurRequestedMuth; add_header Access-Control-Allow-Methods GET,POST,OPTIONS;}

Be careful

Add_header Access-Control-Allow-Origin http://carey.akhack.com;// only allows a single domain name or'*'. If'*'is not recommended, it will lead to security problems at this point. The study on "what to do if the font cannot be displayed when accessing the CSS of the root domain using a subdomain name" is over. I hope to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Domain name font subdomain problem what to do learning method more help practical security next information address article module theory knowledge article website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL MariaDB Shulou Information macOS