angularjs - 从 nginx 提供 Angular SPA 和另一个 index.html

标签 angularjs nginx nginx-location

我有一个 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/

相关文章:

php - 如何设置 Nginx URI 以修复重定向到指定位置的空 URI

c# - 如何使用 AngularJS 在 ASP MVC 中重定向页面?

javascript - Http拦截器工厂导致 "Circular dependency found: factory1 <- $http <- factory2"

image-processing - 如何在Angular JS中的src更改后刷新图像

http - 没有 FastRWeb 的 Rserve .http.request 函数

php - 安装 nginx 后找不到 Laravel 路由

node.js - nginx 响应 "301 moved permanently"

node.js - 找不到 vrrp_instance VI_1 的接口(interface) eth0

javascript - 为什么我应该选择在 AngularJS 中使用服务而不是工厂?

Nginx try_files 在传递变量路径时加载空白页