I have some .rb (Ruby script) files that I link to on my website.

By default, the browser just downloads them to the "Downloads" folder, as it does zip files.

I want the browser to treat it as text, so the Ruby script will show within the browser.

If I do this the normal way however, it does indeed show up in the browser, but the problem is that when the user does a "right-click save as" on the file, the downloaded file gets appended with .txt, such as myscript.rb.txt

Can this .txt extension be avoided with nginx settings?

  • I do this the normal way however What was that normal way? Please update your question on how you made ruby script to show up in the browser. That'd help to see, if anything is wrong in that way. Also, it is preferable to post which browser and OS you used to save. Sometimes, it is the OS and / or the browser that may act weirdly! Sep 28, 2013 at 1:39
  • ... and please tell us which application you use behind nginx; problems lays probably there Sep 28, 2013 at 7:55

1 Answer 1


You can specify in which mimetype you would like nginx to serve files by setting the types directive in your nginx configuration. I don't know about other linux distributions, but if you're using ubuntu, /etc/nginx/mime.types is included by default.

To serve .rb files as text\plain make sure /etc/nginx/mime.types contains the following:

types {
   text/plain    txt rb;

Then you should be able to download the files as txt without the txt extension. I did this using Chrome/Mac OS X and it worked as expected. Note: This means that if you are serving multiple sites with nginx all will return files with the .rb extension as text.

  • Instead of adding specific extensions, is there a way to serve all files as text/plain, except for the ones I configure (so I can exclude .HTML & .PDF, for example)?
    – Evert
    Jul 27, 2022 at 10:50
  • @Evert sure, just add this to the location to override all mime types: types {} default_type text/plain;
    – Domenico
    Sep 17, 2022 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .