public
Last active — forked from sideshowcoder/nginx-font-serving

Nginx header write for serving fonts to firefox cross domain

  • Download Gist
nginx-font-serving
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
For nginx,
 
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
 
Or better way inside virtual host location use,
 
Inside location use
if ($request_filename ~* ^.?/([^/]?)$)
{
set $filename $1;
}
 
if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
add_header Access-Control-Allow-Origin *;
}
 
For Apache
For apache in apache.conf
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
<FilesMatch "\.(ttf|otf|eot)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

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

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.