nginx-将子目录路径重定向到单个(index.html)文件

问题描述:

如何将所有子目录路径重定向到单个index.html文件?

How to redirect all the sub directory path to single index.html file?

这是我想要的nginx配置:

here is what i want nginx configuration:

location /user/* {
    alias /home/vishant/devcenter/baetter-share1;
    index index.html;
}

这意味着,如果我按/user或/user/vishant或/user/xyz/vishant,则应仅显示index.html页面.

this means if i hit /user OR /user/vishant OR /user/xyz/vishant it should render only index.html page.

我编写的代码无法正常工作,但我认为应该与此类似.

The code i have written is not working but what i thought should be similar to this.

location /user/ {
    root /home/vishant/devcenter/baetter-share1;
    try_files /index.html =404;
}

文档:

  • location
  • root
  • try_files