0

We have two services that need to be served with the same hostname but with different paths. https://demoapp.com/login https://demoapp.com/admin/login Have configured ingress rules for both but the ‘/admin’ page is not loading, not sure if the problem is with ingress or Nginx configurations.

ngnix configuration

server {
  location / {
      root /var/www/html/;
      try_files $uri $uri/ /index.html;
  }
}

Docker file

FROM node:14.16.0-alpine as build

ARG NPM_TOKEN

RUN apk add --update nginx

RUN mkdir -p /tmp/nginx/wa-demoapp-fe
RUN mkdir -p /var/log/nginx
RUN mkdir -p /var/www/html/admin
RUN mkdir -p /var/www/html/admin/admin
COPY nginx_config/nginx.conf /etc/nginx/nginx.conf
COPY nginx_config/default.conf /etc/nginx/conf.d/default.conf

WORKDIR /tmp/nginx/wa-demoapp-fe

COPY app/ .
RUN echo "//npm.pkg.github.com/:_authToken=$NPM_TOKEN" > .npmrc
RUN echo "@test:registry=https://npm.pkg.github.com/" >> .npmrc

RUN cp .env.test .env && rm .env.production .env.test .env.development
RUN npm ci && npm run build

RUN cp -r dist/* /var/www/html/admin/admin
RUN cp /var/www/html/admin/admin/index.html /var/www/html/admin/.

RUN chown -R nginx:nginx /var/www/html

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

Ingress config

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-fe
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1  
spec:
  tls:
    - hosts:
        - demoapp.com
      secretName: tls-secret-fe
  rules:
    - host: demoapp.com
      http:
        paths:
          - path: /admin(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: wa-demoapp-fe
                port:
                  number: 80          
          - path: /(.*)
            pathType: Prefix
            backend:
              service:
                name: ab-abc-fe
                port:
                  number: 80              

Did I miss something in the configurations?

Ajeesh Sathyan
  • 337
  • 2
  • 5
  • 15

0 Answers0