簡體   English   中英

Nginx 路由到錯誤的 Angular 應用程序

[英]Nginx routes to wrong Angular application

我的 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/時,angular router似乎要處理app2路由,這導致根應用程序中出現404。

我該怎么辦? 您知道防止此問題的設置嗎? 這是 NGINX 的問題嗎?

先感謝您!

問候

斯特凡

我的 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/時,angular router似乎要處理app2路由,這導致根應用程序中出現404。

我應該怎么辦? 您知道防止此問題的設置嗎? 這是 NGINX 的問題嗎?

先感謝您!

問候

斯特凡

我通過在 angular Service Worker 配置 ngsw-config.json 中聲明第二個應用程序來解決這個問題。

Service Worker 甚至在訪問 nginx 反向代理之前就進行了干擾。

在惰性資產組中聲明第二個應用程序解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM