1、当location配置root 时会自动把location追加到后面,
如前端代码static等代码放在/data/www/abc/下面
则location配置为:
location /abc/ {
root /data/www/;
}
root /data/www/abc/; 配置是错误的。
2、由于多个前端项目放在同一个域名下,所以location用二级目录做了区分,首页访问路径为:www.xxxx.com/abc/,
当时访问项目路由时无法刷新访问,浏览器会报404,url为:www.xxxx.com/abc/list,但是通过前端首页是可以访问list的。
这个原因是list在nginx寻找时,根本不存在,只有前端路由存在。
由于前段没有路由到index.html所以try_files使用 index.html也无法访问,后改为路由到首页根路径/abc/就行了,配置:
location /abc/ {
root /data/www/;
try_files $uri $uri/ /abc/;
}
其他参考:
location / {
root /data/abc/
try_files $uri /index.html;
}