【问题标题】:Nginx routes to wrong Angular applicationNginx 路由到错误的 Angular 应用程序
【发布时间】:2021-01-08 05:34:49
【问题描述】:

我的 Angular 10 应用程序的 NGINX 配置有问题。 似乎 nginx 配置中的以下块与配置的所有其他位置混淆。

        location / {
                alias /var/www/html/myapp/;
                try_files $uri $uri/ /index.html =404;
                add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
        }

根路径上的这个webapp打开一次后,不先清除浏览器缓存,就无法访​​问其他应用了。

其他应用的配置方式类似:

location /app2/ {
                add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
                alias /var/www/html/app2/;
                try_files $uri /$uri/ index.html =404;
        }

当我打开 app1 后打开 http://host/app2/ 时,角度路由器似乎想要处理 app2 路由,这导致根应用程序中出现 404。

我该怎么办?您知道防止此问题的设置吗? 这是 NGINX 的问题吗?

提前谢谢你!

问候

斯蒂芬

【问题讨论】:

    标签: angular nginx configuration routes router


    【解决方案1】:

    我通过在 Angular Service Worker 配置 ngsw-config.json 中声明第二个应用程序来解决此问题。

    Service Worker 甚至在访问 nginx 反向代理之前就进行了干预。

    在惰性资产组中声明第二个应用程序解决了这个问题。

    【讨论】:

      【解决方案2】:

      确定

      root /usr/share/nginx/html;
      

      在服务器块而不是位置块中定义

      【讨论】:

      • 感谢您的回答。服务器块中已经定义了一个根。
      猜你喜欢
      • 1970-01-01
      • 2017-02-28
      • 2020-08-31
      • 2020-12-06
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      相关资源
      最近更新 更多