Fonts on another domain are blocked by CORS (nginx and Apache)
Font from origin has been blocked from loading by Cross-Origin Resource Sharing policyShort answer
Fonts loaded with @font-face from another origin are fetched with CORS, so the font server must send Access-Control-Allow-Origin. In nginx use add_header with always, and watch inheritance: one add_header in a location drops the ones above. In Apache use Header set. Send Vary: Origin when you echo origins.
Fix it fast
1Find out which cause you have
Ask the font server for the file with an Origin header, as the browser does, and read the headers back.
curl -s -D - -o /dev/null \ -H "Origin: https://www.example.com" \ https://static.example.net/fonts/site.woff22Match what you see, then jump to its fix
- 1
The curl output has no Access-Control-Allow-Origin lineThe nginx font location sends no allow-origin headerFix - 2
The header is set at server level, yet font responses lack it, and the font location also sets Cache-Control or Expires headers with add_headerAnother add_header in the same block hides the CORS headerFix - 3
Apache serves the file but the curl output shows no allow-origin headerApache has no Header rule for the font, or only for success codesFix - 4
The font works for one site but fails for another, or fails only after a cache layer was addedA cache serves a font response made for another originFix
- 1
What does the error look like?
Font from origin has been blocked from loading by Cross-Origin Resource Sharing policyReason: CORS header 'Access-Control-Allow-Origin' missing
Cause 1 of 4
The nginx font location sends no allow-origin header
1Check
Search the nginx config for the header. nginx adds it only if you tell it to.
grep -R -n "Access-Control" /etc/nginx/2Fix
Add the header in the location or server that serves the fonts. Use always so the header is also sent on error and redirect codes that add_header skips by default.
location /fonts/ {
add_header Access-Control-Allow-Origin "https://www.example.com" always;
}3Verify
Test the config, reload and repeat the first-step request.
sudo nginx -t && sudo systemctl reload nginxConfirmed by nginx.org
Cause 2 of 4
Another add_header in the same block hides the CORS header
1Check
add_header directives are inherited from the level above only if the current level defines none. A single add_header in the location drops every inherited one.
sudo nginx -T | grep -n -E "location|add_header"2Fix
Repeat the CORS add_header inside the location that holds the other add_header lines, or on nginx 1.29.3 or later set add_header_inherit merge in that location.
location /fonts/ {
add_header Cache-Control "public, max-age=31536000" always;
add_header Access-Control-Allow-Origin "https://www.example.com" always;
}3Verify
Reload and request the font again.
curl -s -D - -o /dev/null -H "Origin: https://www.example.com" https://static.example.net/fonts/site.woff2 | grep -i -E 'access-control|cache-control'Confirmed by nginx.org
Cause 3 of 4
Apache has no Header rule for the font, or only for success codes
1Check
Check that mod_headers is loaded and look for existing Header lines.
grep -R -n "Access-Control" /etc/apache2/2Fix
Make sure mod_headers is enabled and set the header. Header always puts it in the table that is also used for error responses; plain Header uses the onsuccess table. Use set rather than add so the header is not duplicated.
# in the site config or .htaccess
Header always set Access-Control-Allow-Origin "https://www.example.com"3Verify
Reload Apache, then repeat the first-step request.
curl -s -D - -o /dev/null -H "Origin: https://www.example.com" https://static.example.net/fonts/site.woff2 | grep -i access-controlConfirmed by httpd.apache.org
Cause 4 of 4
A cache serves a font response made for another origin
1Check
When the allowed origin changes per request, the response differs by the Origin request header, and caches need Vary: Origin to know it.
curl -s -D - -o /dev/null -H "Origin: https://other.example.org" https://static.example.net/fonts/site.woff2 | grep -i -E 'access-control|vary'2Fix
Send Vary: Origin along with the allow-origin header whenever the value is picked from the request, or use a single fixed origin.
# nginx
add_header Vary Origin always;
# Apache
Header set Vary Origin3Verify
Request the font with two different Origin values and confirm each response matches its own origin.
curl -s -D - -o /dev/null -H "Origin: https://www.example.com" https://static.example.net/fonts/site.woff2 | grep -i -E 'access-control|vary'Confirmed by developer.mozilla.org
How do I stop it coming back?
- Host fonts on the same origin as the site when you can, so no CORS is needed.
- Keep the allowed origins in one config include shared by every font location.
- Check the font URL with curl and an Origin header after each server or CDN change.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
Related fixes
Web apps
The browser blocks your API response: no Access-Control-Allow-Origin header
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.example.com/orders. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
The browser received the response but refused to hand it to your script, because it did not carry an Access-Control-Allow-Origin header naming the page's origin.
4 causes, each with a fixWeb apps
Firefox blocks a cross-origin request even though the CORS headers are set
Reason: Multiple CORS header 'Access-Control-Allow-Origin' not allowed
Firefox puts a Reason in the console message, and that text is the diagnosis.
5 causes, each with a fixWeb apps
WordPress media upload fails with "Unexpected response from the server"
413 Request Entity Too Large
WordPress shows this message when the upload request did not come back as the JSON it expects.
3 causes, each with a fixWeb apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fixWeb apps
A POST to a Google Apps Script web app returns 405 or a CORS error
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.
3 causes, each with a fixWeb apps
OpenAPI does not work in an ASP.NET Core minimal API
404 Not Found at /openapi/v1.json
ASP.NET Core 9 and later generate OpenAPI documents with the Microsoft.AspNetCore.OpenApi package: AddOpenApi registers it and MapOpenApi serves /openapi/v1.json.
3 causes, each with a fix