Dean Winchester
Dean Winchester

Reputation: 659

Nginx try_files & rewrite & content type

I'm currently migrating from lighttpd to nginx. I've got some weird files (don't ask why): 1. say a file named 'news', which actually should be more like news.txt 2. a file named '.html', which actually should be index.html

With lighttpd, simply rewrite those things would work. Nginx would still locate those files with try_files or rewrite, but I've got no control of the content type returned. I mean if the file is named '.html', the content type is 'application/octet-stream'.

I know I can use more_set_headers to achieve that, but is there any other way to do that? I mean why does nginx think a file named '.html' not an html file?

Upvotes: 1

Views: 2105

Answers (1)

VBart
VBart

Reputation: 15110

I mean why does nginx think a file named '.html' not an html file?

A dot at the beginning in unix-like systems is usually used as the indicator of hidden files. In this case, a part after the dot isn't file extension.

I know I can use more_set_headers to achieve that, but is there any other way to do that?

You should use the default_type directive instead of 3-rd party modules.

For example:

location =/.html {
    default_type text/html;
}

Upvotes: 1

Related Questions