我正在尝试为我的angular 8应用程序构建一个docker映像,然后使用nginx reverse_proxy重定向呼叫。呼叫已成功重定向到所需的位置,但是当我刷新任何其他URL时,索引却找不到404错误。 这是我用来构建角度docker映像的dockerfile
### STAGE 1: Build ###
FROM node:12.7-alpine AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY --from=build /usr/src/app/dist/searchService-front /usr/share/nginx/html
这是用于构建nginx图像的配置
worker_processes 1;
events { worker_connections 1024; }
http {
upstream subscriber-service {
server subscriber-service:8090;
}
upstream searchappfront {
server searchappfront:80;
}
upstream searchservice {
server searchservice:8080;
}
server {
listen 80;
# listen 31103;
server_name localhost;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
location /api {
proxy_pass http://subscriber-service;
}
location / {
proxy_pass http://searchappfront;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /subscriber {
proxy_pass http://searchservice;
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}