[英]Nginx and Angular 404 on assets
我有一個 Angular 9 應用程序,它的基本 href 是“./”。 Nginx 僅在 /route1/route2/ 中提供該應用程序與 nginx 配合良好,我可以轉到 localhost:8080/route1/route2 並且角度路由開始正常工作。 我發現的問題是找不到資產。 所以現在,組件被正確加載但沒有資產。
資產文件夾在 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
文件有關。 確保在angular.json
資產數組中包含src/assets
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.