node.js - 资产上的 Nginx 和 Angular 404
问题描述
我有一个基本 href 为“./”的 Angular 9 应用程序。Nginx 仅在 /route1/route2/ 中服务 该应用程序与 nginx 一起正常工作,我可以转到 localhost:8080/route1/route2 并且角度路由开始正常工作。我发现的问题是找不到资产。所以现在,组件被正确加载但没有资产。
assets 文件夹在 src/ 下
Nginx 配置文件:
worker_processes 4;
events { worker_connections 4096; }
http {
server {
listen 8080;
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
location /route1/route2 {
try_files $uri /app/index.html;
}
}
}
Dockerfile:
ARG mode
### STAGE 1: Build ###
FROM node:alpine AS build
COPY package.json package-lock.json ./
RUN npm install && mkdir /app-ui && mv ./node_modules ./app-ui
WORKDIR /app-ui
COPY . .
RUN npm run ng build -- --deploy-url=/app/
### STAGE 2: Run ###
FROM nginx:alpine
# Copy the default nginx.conf provided by the proyect
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
## Remove default nginx index page
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build /app-ui/dist /usr/share/nginx/html
更新!
我发现图像在 /localhost:8080/app/assets/... 现在的问题是服务器正在尝试从 ...8080/route1/route2/assets... 加载资产
解决方案
问题可能出在angular.json
文件上。确保包含src/assets
in assets 数组angular.json
推荐阅读
- php - Docker 容器上的 Couchbase PHP SDK 2.6
- spring-boot - 如何在轴突框架中查询没有视图表的状态存储聚合?
- image - Flutter - 如何在列表视图中显示多个图像和 pdf?
- highcharts - highcharts网络图表上的自定义悬停/工具提示数据
- printing - How to create raspberry pi as printing proxy
- python - 如何使用 Sequitur G2P 作为 python 模块?
- r - 能够在数据帧上使用行名称字符串找到行,但“%in%”和“哪个”函数无法在 rownames() 向量中找到相同的行?
- javascript - CodenameOne 问题在 BrowserComponent 中处理 iOS 12 和 13 上的鼠标事件
- types - 在 Fortran 中使用带有列表参数的类型绑定函数导致奇怪的内存丢失
- c++ - 在二维数组中新建后的星号