Docker Nginx proxy_pass总是返回索引页面

时间:2020-10-07 02:20:15

标签: docker nginx docker-compose

我在docker中包装了两个有角度的应用程序

FROM node:11-alpine as builder
WORKDIR /application
RUN npm config set unsafe-perm true
RUN npm install -g @angular/cli@7.2.0
RUN apk update && apk add gettext
COPY package.json angular.json tsconfig.json tslint.json package-lock.json ./
RUN npm install
COPY src src

ARG BASE_HREF=/
ARG API_URL
ARG CLIENT_ID
RUN envsubst < ./src/environments/environment.prod.ts > ./src/environments/environment.prod.ts.tmp && mv ./src/environments/environment.prod.ts.tmp ./src/environments/environment.prod.ts
RUN ng build --prod --output-path=dist --base-href=$BASE_HREF

FROM nginx:stable-alpine
COPY nginx /etc/nginx/conf.d/
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /application/dist /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]

我正在尝试使用docker-compose部署它们

  frontend:
    build: ./frontend/user
    restart: always
    networks:
      - app-network

  admin:
    build: ./frontend/admin
    restart: always
    networks:
      - app-network

Nginx配置

    listen 80;
    server_name my_site.com;

    include /etc/nginx/mime.types;

    gzip on;
    gzip_min_length 1000;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;


    location / {
        proxy_pass http://frontend/;
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /admin {
        proxy_pass http://admin/admin/;
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

关于位置/正确的响应,一切正常。 在位置/ admin上,所有请求都返回内容类型为text / html

的索引页

你为什么这么认为?

0 个答案:

没有答案