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

我在nginx内设置这个别名很麻烦,正确显示我的网站.

我关心的网站应该可以从mywebsite.com/mr访问,并且不同于位于mywebsite.com/的网站.该网站位于/ fullpath(简化简称)网站需要提供三种内容:

>位于/fullpath/index.html的索引文件.
>其他html文件(浏览器中不显示.html扩展名).
>静态资源(js / css / img)位于/ fullpath和子目录中.

我尝试改变了try_files中匹配的顺序,发现它们都工作的情况,而不是在同一时间:

location /mr {
  default_type "text/html";
  alias /fullpath;

  # with this one 1 and 3 work
  # try_files $uri/index.html $uri.html $uri; 

  # with this one 2 and 3 work
  # try_files $uri $uri.html $uri/index.html;

  # with this one 1 and 2 work
  try_files $uri.html $uri/index.html $uri;
}

当一个人不工作404的.有人知道我能如何正确地提供各种文件?

显然是别名和try_files don’t work together.但是,我不认为你需要使用别名.

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

哪个会尝试:

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

我认为根指令使用try文件,但无法测试.

server{
    location /mr {

        root /home/mysite/fullpath;

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

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。