我在单独的文件夹中运行了几个SPA以及一些静态文件。 结构如下:
| |- index.html |- foobar.html |---- SPA1/ | |- index.html | |---- SPA1_1/ | |- index.html |---- SPA2/ |- index.html
预期的行为是:
/SPA1/SPA1_1/foo/bar
与SPA1/SPA1_1/index.html
SPAx/index.html
服务所有的SPAx/foo/bar
/index.html
服务/not_exist
/foobar.html
提供/foobar.html
总之,我希望nginx按顺序尝试以下path:
$uri
$uri
最亲密的父母 有没有什么办法可以达到这个目的而不需要为每个SPA目录指定规则?
您可以通过每次删除目录path来recursion地重写URI,直到findindex.html
文件。 这将是一个内部循环,不会发生外部redirect。
例如:
location / { try_files $uri $uri/index.html @rewrite; } location @rewrite { rewrite ^(.*)/.+ $1/ last; }