首页 > 解决方案 > 使用 /assets 文件夹在 URI 中提供 Angular

问题描述

我在为 nginx 提供 Angular 服务时遇到了一些困难。问题是,在基本 URI 中有一个 api,nginx 代理将请求传递给它。然后在 URI "/interface" 后面加载除 "assets" 文件夹之外的所有内容。因为它现在似乎被很好地引用了。

我用来构建角度网页的命令是:

RUN ng build --configuration=dev --output-path=dist --base-href=/interface/

我的 nginx 配置是:

location /interface {
    alias   /usr/share/nginx/html;
    try_files $uri$args $uri$args/ $uri/ /interface/index.html;
}

我的输出是这样的:

在此处输入图像描述

这个assets文件夹搞砸了。

编辑1:NGINX LOGS_>

nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:43 +0000] "GET /interface HTTP/1.1" 301 169 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:43 +0000] "GET /interface/ HTTP/1.1" 200 1218 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /interface/styles.32540aa30747f5274629.css HTTP/1.1" 304 0 "https://192.168.0.54/interface/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /interface/polyfills-es2015.ffa9bb4e015925544f91.js HTTP/1.1" 304 0 "https://192.168.0.54/interface/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /interface/main-es2015.1d67bcd1e0c93a4ef3b3.js HTTP/1.1" 304 0 "https://192.168.0.54/interface/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /interface/runtime-es2015.cdfb0ddb511f65fdc0a0.js HTTP/1.1" 304 0 "https://192.168.0.54/interface/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /assets/i18n/en.json HTTP/1.1" 502 157 "https://192.168.0.54/interface/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 2020/11/10 12:01:44 [error] 95#95: *92 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.28, server: windtec.nexusgeografics.com, request: "GET /assets/i18n/en.json HTTP/1.1", upstream: "http://192.168.0.54:8000/assets/i18n/en.json", host: "192.168.0.54", referrer: "https://192.168.0.54/interface/"
nginx      | 2020/11/10 12:01:44 [error] 95#95: *92 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.28, server: windtec.nexusgeografics.com, request: "GET /assets/img/logo%20(1)@2x.png HTTP/1.1", upstream: "http://192.168.0.54:8000/assets/img/logo%20(1)@2x.png", host: "192.168.0.54", referrer: "https://192.168.0.54/interface/login"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /assets/img/logo%20(1)@2x.png HTTP/1.1" 502 157 "https://192.168.0.54/interface/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /assets/img/Grupo%2042.svg HTTP/1.1" 502 157 "https://192.168.0.54/interface/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /assets/img/Grupo%2043.svg HTTP/1.1" 502 157 "https://192.168.0.54/interface/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 2020/11/10 12:01:44 [error] 95#95: *92 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.28, server: windtec.nexusgeografics.com, request: "GET /assets/img/Grupo%2042.svg HTTP/1.1", upstream: "http://192.168.0.54:8000/assets/img/Grupo%2042.svg", host: "192.168.0.54", referrer: "https://192.168.0.54/interface/login"
nginx      | 2020/11/10 12:01:44 [error] 95#95: *93 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.28, server: windtec.nexusgeografics.com, request: "GET /assets/img/Grupo%2043.svg HTTP/1.1", upstream: "http://192.168.0.54:8000/assets/img/Grupo%2043.svg", host: "192.168.0.54", referrer: "https://192.168.0.54/interface/login"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /interface/fons_login.f065d97fdb8c6cd8da06.jpg HTTP/1.1" 304 0 "https://192.168.0.54/interface/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"
nginx      | 192.168.0.28 - - [10/Nov/2020:12:01:44 +0000] "GET /interface/favicon.ico HTTP/1.1" 200 948 "https://192.168.0.54/interface/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0" "-"

标签: angularnginx

解决方案


推荐阅读