Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
nginx in kubernetes does not redirect for one app, but does for another

I have the following deployment yaml files:

foo.yaml:

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
    name: foo-ingress
    annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
        nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
        nginx.ingress.kubernetes.io/rewrite-target: /$1 
        nginx.ingress.kubernetes.io/configuration-snippet: |
            rewrite ^(/apps/foo)$ $1/ redirect;
spec:
    rules:
    - host: myhost
      http:
        paths:
        - path: /apps/foo/(.*)
          backend:
            serviceName: foo-service
            servicePort: 8080
bar.yaml:

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
    name: bar-ingress
    annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
        nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
        nginx.ingress.kubernetes.io/rewrite-target: /$1 
        nginx.ingress.kubernetes.io/configuration-snippet: |
            rewrite ^(/apps/bar)$ $1/ redirect;
spec:
    rules:
    - host: myhost
      http:
        paths:
        - path: /apps/bar/(.*)
          backend:
            serviceName: foo-service
            servicePort: 8080

I applied each file with

kubectl apply -f foo.yaml

kubectl apply -f bar.yaml

The problem is that the redirection from /apps/foo to /apps/foo/ (adding the extra slash) works fine. The redirection from /apps/bar does not work. I get a 404.

I opened the generated nginx.conf in the ingress pod, and it's a bit of a mess. I have the following (removed irrelevant parts):

    location ~* "^/apps/foo/(.*)" {
       rewrite ^(/apps/foo)$ $1/ redirect;
    }
    location ~* "^/apps/bar/(.*)" {
       rewrite ^(/apps/bar)$ $1/ redirect;
    }
    location ~* "^/" {
       ...
       rewrite ^(/apps/foo)$ $1/ redirect;
    }

As you can see, the redirection is added both under the / matching (where it works) and also in the more specific matching, where it makes no sense (as it will never get there, given that without a / the rule will not match).

What am I doing wrong in the overall approach? why is the ingress controller adding redirection only to one url?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda