I am trying to serve some webfonts through a PHP script that tells nginx to do an internal redirect using X-Accel-Redirect
.
As the script serves many types of files, I only wish to add the Access-Control-Allow-Origin
header for fonts.
This is a configuration I have tried that works:
location /deploys/ {
internal;
alias /www/deploys/;
expires 1y;
add_header Access-Control-Allow-Origin *;
}
The problem with this approach is that ALL files now contain the Access-Control-Allow-Origin
header. I only want my fonts to have that header.
So, I tried a conditional:
location /deploys/ {
internal;
alias /www/deploys/;
expires 1y;
if ($request_filename ~* ^.?/([^/]?)$)
{
set $filename $1;
}
if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
add_header Access-Control-Allow-Origin *;
}
}
Unfortunately, this does not work (and I suspect it would be due to the internal redirect using `X-Accel-Redirect).
How does one go about appending the Access-Control-Allow-Oirgin
header for some extensions using X-Accel-Redirect
?
It looks like
alias
will change the request file. I did not have time to compile and install theecho
module to verify, but using the following config fixed the problem: