It looks like your Rewrite Target is wrong. Look at this general example from documentation:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: rewrite
namespace: default
spec:
rules:
- host: rewrite.bar.com
http:
paths:
- backend:
serviceName: http-svc
servicePort: 80
path: /something(/|$)(.*)
In this ingress definition, any characters captured by (.*)
will be assigned to the placeholder $2
, which is then used as a parameter in the rewrite-target
annotation.
For example, the ingress definition above will result in the following rewrites:
rewrite.bar.com/something
rewrites to rewrite.bar.com/
rewrite.bar.com/something/
rewrites to rewrite.bar.com/
rewrite.bar.com/something/new
rewrites to rewrite.bar.com/new
In your situation, if you try to access staging.my-domain.com/
, you are rewrited to the same address. Everything is fine. But you can rewrite only this address. You should change your manifest like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
external-dns.alpha.kubernetes.io/hostname: staging.my-domain.com
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /$1
name: nlx-api
spec:
rules:
- host: staging.my-domain.com
http:
paths:
- path: /(.*)
pathType: Prefix
backend:
service:
name: our-api
port:
number: 80
In this situation any characters captured by (.*)
will be assigned to the placeholder $1
(this is first capture group), which is then used as a parameter in the rewrite-target
annotation.