I have the following stanza in my nginx virtual host config. The goal is to only allow direct (deep link) downloads of only video content types, and return a 404 or some other error for anything else:
location ~* ^/webdata/.+(\.mp4|\.m4v|\.mpg|\.mpeg|\.mpg|\.mts|\.avi)$ {
root /srv/data;
}
As you can see the above achieves this rather crudely by matching the end of the requested URL. If it doesn't end in .mp4
, .m4v
, .mpg
, etc. the stanza isn't triggered and the client doesn't get the file.
Ideally I'd like to be able to be able to do something like this (this obviously doesn't work, since $content_type
refers to the content-type HTTP reqest header from the client, and not the content-type of the requested resource, if I am not mistaken):
location /webdata {
if ($content_type =~ 'video/.*')
{
root /srv/data/;
}
}
Is there a way to do this?
Comment: Based on question 577471, it seems like nginx relies purely on filenames/URI, rather than using something like MIME magic to figure out the content type based on actual file content headers, like most modern Linux desktop environments do. If this is true, then this may not be possible.