{"id":2143,"date":"2017-10-02T18:15:14","date_gmt":"2017-10-02T12:45:14","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=2143"},"modified":"2026-09-08T14:40:17","modified_gmt":"2026-09-08T09:10:17","slug":"allow-cross-origin-regioncors-fonts-nginx","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/allow-cross-origin-regioncors-fonts-nginx\/","title":{"rendered":"Allow Cross Origin Region(CORS) for Fonts in NGINX"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When serving web fonts such as <strong>WOFF, WOFF2, TTF, or EOT<\/strong> from an NGINX web server, browsers may block access if the font files are requested from a different domain, subdomain, or CDN. This restriction is enforced by the browser&#8217;s <strong>Cross-Origin Resource Sharing (CORS)<\/strong> policy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common browser errors include:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">No &#8216;Access-Control-Allow-Origin&#8217; header is present on the requested resource.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">or<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Access to font at &#8216;<a href=\"https:\/\/example.com\/font.woff2\" target=\"_blank\" rel=\"noopener\">https:\/\/example.com\/font.woff2<\/a>&#8216; from origin &#8216;<a href=\"https:\/\/www.example.org\" target=\"_blank\" rel=\"noopener\">https:\/\/www.example.org<\/a>&#8216; has been blocked by CORS policy.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">To resolve this issue, you must configure NGINX to send the appropriate <strong>Access-Control-Allow-Origin<\/strong> header for font files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains how to enable CORS for fonts in NGINX and verify that the configuration is working correctly.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, ensure the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>NGINX web server is installed and running.<\/li>\n\n\n\n<li>You have root or sudo access to the server.<\/li>\n\n\n\n<li>Font files are being served by NGINX.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Helpful installation guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ubuntu 16.04 \u2013 Install NGINX, PHP, and MariaDB<\/li>\n\n\n\n<li>CentOS 7 \u2013 Install NGINX, PHP-FPM, and MariaDB<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Enable CORS for Font Files in NGINX<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Open your NGINX virtual host configuration file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/etc\/nginx\/sites-enabled\/default<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following location block inside the server configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">location ~* \\.(eot|ttf|woff|woff2)$ {\n    add_header Access-Control-Allow-Origin *;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Configuration Explanation<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>location ~*<\/code> performs a case-insensitive match.<\/li>\n\n\n\n<li><code>\\.(eot|ttf|woff|woff2)$<\/code> targets common font file extensions.<\/li>\n\n\n\n<li><code>Access-Control-Allow-Origin *<\/code> allows font files to be accessed from any domain.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to restrict access to a specific domain, replace <code>*<\/code> with the allowed origin:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">location ~* \\.(eot|ttf|woff|woff2)$ {\n    add_header Access-Control-Allow-Origin https:\/\/example.com;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Verify NGINX Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before reloading NGINX, validate the configuration syntax:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nginx -t<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Restart NGINX<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apply the changes by restarting or reloading NGINX:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl restart nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl reload nginx<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Verify CORS Headers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use curl to confirm that the header is being sent:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -I https:\/\/yourdomain.com\/fonts\/font.woff2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected response:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Access-Control-Allow-Origin: *<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also verify the response using your browser&#8217;s Developer Tools under the <strong>Network<\/strong> tab.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>CORS header is not appearing<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Verify the location block is inside the correct server block.<\/li>\n\n\n\n<li>Run <code>nginx -t<\/code> to check for configuration errors.<\/li>\n\n\n\n<li>Reload NGINX after making changes.<\/li>\n\n\n\n<li>Clear browser cache and CDN cache if applicable.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fonts still fail to load<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Confirm the font files are being served by NGINX.<\/li>\n\n\n\n<li>Check browser developer console for additional errors.<\/li>\n\n\n\n<li>Verify there are no conflicting location blocks overriding the configuration.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Using Cloudflare or CDN<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your site uses a CDN such as Cloudflare, purge the cache after updating NGINX settings to ensure the new headers are served.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Configuring CORS headers for font files in NGINX is a simple but essential step when serving fonts across domains, subdomains, or CDNs. By adding the <code>Access-Control-Allow-Origin<\/code> header and validating the configuration, you can prevent browser CORS errors and ensure that web fonts load correctly for all users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Following the steps in this guide will help eliminate common font-loading issues and improve the overall user experience on your website.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions (FAQ)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. What is CORS?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CORS (Cross-Origin Resource Sharing) is a browser security mechanism that controls how resources are shared between different domains, subdomains, or origins.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Why do font files require CORS headers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Modern browsers enforce CORS checks on font files. If the font is loaded from a different origin and the required header is missing, the browser blocks access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Is using <code>Access-Control-Allow-Origin *<\/code> safe?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For publicly accessible font files, using <code>*<\/code> is generally acceptable. However, if you need stricter security, specify the exact domain that should be allowed to access the fonts.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">1. Adding Automatic .php Extension in NGINX<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/adding-automatic-extension-php-nginx\/\">Read the guide: Adding Automatic .php Extension in NGINX<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Fix CodeIgniter 404 Errors in NGINX<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/codeigniter-404-error-nginx\/\">Read the guide: Fix CodeIgniter 404 Errors in NGINX<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. Hide Web Server Information and Modify Server Headers in NGINX<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/hide-webserver-informationmodify-server-header-nginx\/\">Read the guide: Hide Web Server Information and Modify Server Headers in NGINX<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team <a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction When serving web fonts such as WOFF, WOFF2, TTF, or EOT from an NGINX web server, browsers may block [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[372,271],"class_list":["post-2143","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-cors","tag-nginx","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-yz","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2143"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2143\/revisions"}],"predecessor-version":[{"id":11538,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2143\/revisions\/11538"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}