【发布时间】:2017-09-07 11:43:43
【问题描述】:
我有一个 react 应用程序(使用 react-router 和 html5 pushstate 路由) 我希望 http://example.com/v2 作为服务器新网站的基本路由
我使用这些 nginx 配置:
这个捕获 /v2 并使用新的 js 文件
location ^~ /v2 {
alias /usr/local/theapp/dist;
try_files $uri $uri/ /v2/index.html;
access_log /var/log/nginx/theapp/acces.web.log;
error_log /var/log/nginx/theapp/error.web.log debug;
}
location ~ ^/(v2)/.+\..+$ {
try_files $uri =404;
alias /usr/local/theapp/dist;
error_log /var/log/nginx/theapp/error.web.log debug;
}
由于第一个位置块,即使是404也会被重定向到v2/index.html,所以第二个位置的目的是处理带有扩展名的uri,所以如果http://example.com/v2/user/profile/picture.jpg不存在,那么我仍然会得到正确的 404 资源未找到错误。
上面的代码显然不起作用,因为^~的优先级高于~。尝试了 2 ~ 但我得到了 try_files 重定向循环:(
【问题讨论】:
标签: html nginx react-router