3

I have a directory on my server which has a bunch of shell scripts. This directory is autoindexed, but when I try to open the files in my browser, they prompt for download instead of opening as text. I can easily map the filetype "sh" to text/plain in the mime.types file, but some of the scripts don't have that sh extension. How can I serve all files in a certain directory as .txt files so that they are opened in the user's browser instead of prompting the user for download?

Edit: adding add_header Content Type text/plain; to that directory's location block does show all of the scripts as text, but it also affects the autoindex page.

  • This is behaviour of your browser use command line tool like curl if you want to get text output. Certain file like pdf, jpg are opened whereas other are downloaded – Rajesh Paudel Jun 02 '21 at 15:08
  • Does this answer your question? [How to add headers to only specific files with nginx](https://stackoverflow.com/questions/16945223/how-to-add-headers-to-only-specific-files-with-nginx) – Rajesh Paudel Jun 02 '21 at 15:26
  • 1
    Use: `types {}` and `default_type test/plain;` – Richard Smith Jun 02 '21 at 15:36

1 Answers1

2

That should be add_header Content-Type text/plain; (instead of add_header Content Type text/plain; , right?)

But you're right about it affecting all files. It even renders HTML as plain text and displays the source when visited with a browser. I'm experiencing the same problem as you have (files with many different extensions, most of which plain text)

Evert
  • 143
  • 6