我正在尝试构建一个利用HTML5 App Cache的单页应用程序,它将为每个不同的URL缓存一个全新版本的应用程序,因此我必须将所有人重定向到/我的应用程序之后路由它们(这是使用的解决方案)在devdocs.io).
这是我的nginx配置.我希望所有的请求发送一个文件,如果存在的话,重定向到我的API在/auth和/api,和重定向所有其他请求的index.html.为什么以下配置导致我的浏览器说有重定向循环?如果用户点击位置块#2并且他的路线与静态文件不匹配,他将被发送到位置块#3,它会将他重定向到"/",它应该击中位置块#1并提供index.html,对吗?导致重定向循环的原因是什么?有没有更好的方法来实现这一目标?
root /files/whatever/public;
index index.html;
# If the location is exactly "/", send index.html.
location = / {
try_files $uri /index.html;
}
location / {
try_files $uri @redirectToIndex;
}
# Set the cookie of the initialPath and redirect to "/".
location @redirectToIndex {
add_header Set-Cookie "initialPath=$request_uri; path=/";
return 302 $scheme://$host/;
}
# Proxy requests to "/auth" and "/api" to the server.
location ~* (^\/auth)|(^\/api) {
proxy_pass http://application_upstream;
proxy_redirect off; …Run Code Online (Sandbox Code Playgroud)