angular - 使用 /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" "-"
解决方案
推荐阅读
- c - 共享内存中的简单检查返回 SIGSEGV 错误 008b
- php - 表单未收集用户输入,即使我输入了有效的表和列,查询也无法正常工作
- java - 如何使用 Cucumber 和 Rally 集成自动更新 Rally 测试用例?
- bash - 如何在我的 git 环境中修复 pre-commit-msg?
- optimization - 如何使用严格的不等式比较浮点变量?
- javascript - 我的 .on Swipe 在中断之前只能工作一次并且必须刷新所有内容 - JQuery Mobile / Javascript
- xml - 创建maven项目时如何修复“找不到前缀'原型'的插件”错误
- java - 如何减少工具栏上的文本和汉堡图标之间的差距
- c# - 路径中的非法字符
- bash - tr 命令在 bash 脚本中失败