在nginx中返回源文本

时间:2013-01-29 03:05:38

标签: mod-rewrite nginx mime-types

我希望能够将filename.jadefilename.styl作为文字mime类型返回。

nginx需要提供/source目录中的任何内容,就好像它是文本

一样

现在使用符号链接

/source/subdir/page1.jade.txt => ../subddir/page1.jade

并在nginx

location ~ ^/source/ {
  expires 1d;
  try_files $uri.txt 404;
}

这可行,但不是很优雅,并且需要重新创建符号链接

这是如何在nginx完全实现的?是否有必要使用rewrite从路径中删除/source目录?

1 个答案:

答案 0 :(得分:1)

最好使用location指令和types指令作为示例belove:

location ~ /*.jade {
   types          { }
   default_type   text/plain;
   try_files $uri =404;
}

location ~ /*.styl {
   types          { }
   default_type    text/plain;
   try_files $uri =404;
}

这两个location块都设置为不使用任何MIME类型并使用默认的text/plain MIME类型,因此它应该适合您。

我希望这会有所帮助