且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在nginx中提供html文件而不在此别名设置中显示扩展名

更新时间:2023-11-29 19:55:04

Apparently alias and try_files don't work together. However, I don't think you need to use alias.

location /mr {
  default_type "text/html";
  try_files  /fullpath/$uri /fullpath/$uri.html /fullpath/$uri/index.html  /fullpath/index.html;
}

Which would try:

  • Exact file.
  • File with .html added.
  • Index in the path.
  • Default index.

I think the root directive does work with try files but am unable to test.

server{
    location /mr {

        root /home/mysite/fullpath;

        default_type "text/html";
        try_files  $uri $uri.html $uri/index.html index.html;
    }
}