A good[ish] website
Web development blog, loads of UI and JavaScript topics
Here’s how to add Content-Type: text/plain
with NGINX to all files inside a given directory.
If you don’t want to download a file, nor execute it, but just view it as raw text in browser, in same fashion as .txt
files. You can tell the web server to render it as plain text, but setting content type in the headers:
Content-Type text/plain
With NGINX you can do it like this:
location test.php {
add_header Content-Type text/plain;
}
That goes into your NGInx Server Block file. It only targets a single file, some regex can be added to target all files in a specific directory for instance:
# Target code dir
location /code/ {
# All files in it
location ~* {
add_header Content-Type text/plain;
}
}
Comments would go here, but the commenting system isn’t ready yet, sorry.