Nginx + @font-face + Firefox / IE9

http-headersnginx

Just transferred my site from a shared hosting to Linode's VPS, and I'm also completely new to nginx, so please don't be harsh if I missed something evident ^^

I've got my WordPress site running pretty well on nginx & MaxCDN, but my @font-face fonts (served from cdn.domain.com) stopped working in IE9 and FF (@font-face failed cross-origin request. Resource access is restricted.)

I've googled for hours and tried adding all of the following to my config files:

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


location ^/fonts/ { 
    add_header Access-Control-Allow-Origin *; 
}


location / { 
    if ($request_filename ~* ^.*?/([^/]*?)$) 
    { 
        set $filename $1; 
    } 

    if ($filename ~* ^.*?\.(eot)|(otf)|(ttf)|(woff)$){ 
        add_header 'Access-Control-Allow-Origin' '*'; 
    } 
}

Of course, I've restarted nginx after every change.

The headers just don't get sent at all no matter what I do.

I have the default Ubuntu apt-get build nginx which should include the headers module by default… How do I check what modules are installed, or what else could be causing this error?

UPDATE:

I've tried running curl -I [location-of-the-font] and it does return Access-Control-Allow-Origin: * but the header is not visible in Chrome's Network panel and the fonts still don't work in FF & IE9 (CSS3117: @font-face failed cross-origin request. Resource access is restricted.) – Any ideas what could be causing this?

Best Answer

The only suggestion that could be given is that you must, (1), ensure you clear the cache within your browser, and, (2), ensure that add_header is present at the appropriate level.

There's not much point in defining it everywhere. If all your fonts are served from within location /fonts, then that's the only location where you must declare the appropriate add_header, and you must also ensure that no further sub-locations have any other add_header directives, either, because that would reset all prior add_header directions at the preceding levels.