Wrong mimetype when served from nginx

Maxim Dounin mdounin at mdounin.ru
Sun Jul 12 04:57:51 UTC 2015


On Fri, Jul 10, 2015 at 08:00:06AM +0200, Cédric Jeanneret wrote:

> Hello,
> I have a small issue with my nginx (1.2.1) configuration:
> some files are served as "application/octet-stream" while they are
> detected as "text/plain" by "mimetype <file>" command.
> File names are just "1", "2", and so on.
> Is there a way to enforce mimetype for those files?

MIME types are determinded by nginx according to file extensions.  
For files without extensions the default type is used.  That is, 
if you want nginx to serve some files without extensions as 
text/plain, you'll have to set

    default_type text/plain;

in an appropriate context.

> I thought about something like this:
> location ~ /path/to/file/[0-9]+ {
>   types {}
>   default_type text/plain;
> }
> but after that, I get a 404 — what did I wrong?

Your error log is likely to contain some details.  Looking into it 
usually helps to understand what goes wrong.

Most likely, you have "root" configured in a location which was 
previously used to handle requests.  There is no "root" in the new 
location you've added, so server default will be used (which is 
likely to be unset too).  You'll have to either replicate the 
"root" directive in the location you are adding with default_type, 
or move it to the server{} level.

See these links for some additional hints:


Maxim Dounin

More information about the nginx mailing list