且构网

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

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

更新时间:2023-11-29 20:08:58

显然是别名和 try_files don'一起工作.但是,我认为您不需要使用别名.

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;
}

哪个会尝试:

  • 确切的文件.
  • 添加了 .html 的文件.
  • 路径中的索引.
  • 默认索引.

我认为 root 指令确实适用于 try 文件,但无法测试.

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;
    }
}