Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure nginx to show file content instead of downloading it?

Tags:

nginx

I have a directory index configured and every time I click a file it gets downloaded.

I want to tell nginx to show the content for text files instead of downloading them.

I still want the download to work when I use wget on those text files.

How can I do that?

like image 823
guy mograbi Avatar asked Mar 26 '14 19:03

guy mograbi


1 Answers

Just set the content type in the location block.

In my case I want to serve a VERSION file, but by default the browser downloads it (because it's served as application/x-octet-stream). If I make nginx send it with a Content-type of text/plain, the browser will display it instead of downloading it.

location = /VERSION {
    root /usr/share/nginx/html;
    add_header Cache-Control 'must-revalidate';
    add_header Content-Type text/plain;
}
like image 187
Matthias Avatar answered Sep 20 '22 23:09

Matthias