Welcome! Log In Create A New Profile

Advanced

Re: Wrong mimetype when served from nginx

Maxim Dounin
July 12, 2015 12:58AM
Hello!

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:

http://nginx.org/r/location
http://nginx.org/r/root

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Wrong mimetype when served from nginx

Cédric Jeanneret July 10, 2015 02:02AM

Re: Wrong mimetype when served from nginx

Maxim Dounin July 12, 2015 12:58AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 167
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready