Kubernetes nginx re-write per path

9/17/2021

I'm trying to setup nginx ingress for the following scenario:

A service (svc1) with multiple paths:

example.com/api/foo-> /api/foo (sv1)

example.com/api/foo/hangfire -> /hangfire (sv1)

example.com/api/bar -> /api/bar (sv2)

I've been trying to play around with the rewrite and regex to no avail - below is what I've got.

ingress:
  enabled: true
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: "/api/foo/$1"
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /api/foo/hangfire
        backend:
          serviceName: svc1
          servicePort: 80
      - path: /api/foo/(.*)
        backend:
          serviceName: svc1
          servicePort: 80
      - path: /api/bar/
        backend:
          serviceName: svc2
          servicePort: 80
-- Chris L
kubernetes
nginx
nginx-ingress
regex
url-routing

0 Answers