我有一个 SPA 并通过 Nginx 提供服务,效果很好。我在子文件夹中也有一个简单的 index.html。
Spa 链接到 index.html 以显示一个子应用程序,该应用程序是简单的 html,带有自己的 css/js。当尝试浏览子文件夹 app 时,nginx 重定向到基本 spa。
nginx 配置
location / {
try_files $uri $uri/ /index.html =404;
}
location /3d-viewer/ {
try_files $uri $uri/ /3d-viewer/index.html;
}
感谢您的帮助。
最佳答案
在 Angular 应用程序配置中 https://angular.io/api/common/APP_BASE_HREF
import {Component, NgModule} from '@angular/core';
import {APP_BASE_HREF} from '@angular/common';
@NgModule({
providers: [{provide: APP_BASE_HREF, useValue: '/3d-viewer'}]
})
class AppModule {}
nginx.conf
location /3d-viewer {
alias /var/www/html/3d-viewer;
try_files $uri $uri/ /index.html =404;
expires 0;
add_header Cache-Control no-cache;
add_header X-Cache-Status REVALIDATED;
break;
}
关于angularjs - 从 nginx 提供 Angular SPA 和另一个 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44089691/