我有一个单页 Web 应用程序。我想设置 nginx 直接为文件夹下的文件提供服务,对于所有其他请求,我希望它为单个 html 文件提供服务。我想要实现的设置如下:
.
.
.
location /static/ {
# Serve directly here
}
location / {
# Serve single file here (index.html), without changing the path
}
.
.
.
Run Code Online (Sandbox Code Playgroud)
我发现的类似问题的答案建议使用 url 重写,但据我所知,这会将用户重定向到新的 url,从而更改路径。
我想要的是,除了以静态开头的内容之外,无论用户键入什么,nginx 都会在不更改路径的情况下提供 index.html 文件,因为我将使用路径变量将动态内容加载到网页。
Ale*_*Ten 14
最简单的方法是
location / {
try_files /index.html /index.html;
}
Run Code Online (Sandbox Code Playgroud)