Nginx cross domain configuration method using font files

  • 2020-05-10 23:14:42
  • OfStack

Today, when using the subdomain to access the CSS of the root domain, it was found that the font could not be displayed. After ensuring that the path loading of CSS and Font fonts was no problem, it was basically determined that it was because of cross-domain problems.

Add the address allowed by Access-Control-Allow-Origin via the Nginx module HttpHeadersModule.

The solution

In the conf directory of Nginx, modify nginx.conf or the corresponding domain conf under vhost, and add the following code:


location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}

For more details on Nginx's cross-domain configuration, see the article below.

Wide-open CORS config for nginx


Related articles: