# Wrong mimetype when served from nginx

**URL:** <https://www.ruby-forum.com/t/wrong-mimetype-when-served-from-nginx/242636>\
**Category:** NGINX\
**Created:** [July 10, 2015, 8:00am UTC](https://www.ruby-forum.com/t/wrong-mimetype-when-served-from-nginx/242636 "2015-07-10T08:00:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [July 10, 2015, 8:00am UTC](https://www.ruby-forum.com/t/wrong-mimetype-when-served-from-nginx/242636/1 "2015-07-10T08:00:51Z")

</div>

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 " command.

File names are just “1”, “2”, and so on.

Is there a way to enforce mimetype for those files?

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?

Thanks for your support!

Cheers,

C.

---

<div class="post-metadata">

**Author:** ![CSSdric\_Jeanneret](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9de0a6/32.png) [@CSSdric\_Jeanneret](https://www.ruby-forum.com/u/CSSdric_Jeanneret)\
**Post date:** [July 12, 2015, 6:58am UTC](https://www.ruby-forum.com/t/wrong-mimetype-when-served-from-nginx/242636/2 "2015-07-12T06:58:18Z")

</div>

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 ” 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:

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#location)**
>
> This directive appeared in version 1.11.8.

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#root)**
>
> This directive appeared in version 1.11.8.

–  
Maxim D.

> **[nginx](http://nginx.org/)**
