Search code examples
mod-rewritenginxmime-types

in nginx return source as text


I wish to be able to return filename.jade and filename.styl as text mime type.

nginx needs to serve anything in the /source directory as if it were text

right now using symlinks

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

and in nginx

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

this works, but not very elegant, and the symlinks need to be recreated

how is this accomplished purely in nginx? is it necessary to use rewrite to chop off the /source directory from the path?


Solution

  • It will be better for you to use specific location directive with types directive as example belove:

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

    Here for both location blocks you set to do not use any MIME-Types and to use as default text/plain MIME-Type so it should work for you.