Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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! – Pothi Sep 28 '13 at 1:39
... and please tell us which application you use behind nginx; problems lays probably there – that guy from over there Sep 28 '13 at 7:55
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.