Home > other >  How can I modify the proxied path in a Kubernetes NGINX Ingress
How can I modify the proxied path in a Kubernetes NGINX Ingress

Time:06-02

Basically, I'm trying to do this:

location / {
        proxy_pass https://externaldomain.com/api/;
}

without passing nginx a server-snippet, through the spec instead.

So if a request hits https://myingress.com/endpoint, my cluster serves them the content from https://externaldomain.com/api/endpoint

I have an ExternalName service set up:

apiVersion: v1
kind: Service
metadata:
  name: api-proxy
spec:
  type: ExternalName
  externalName: externaldomain.com

And an Ingress path to reach it, but without the path change:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/upstream-vhost: "externaldomain.com"
    nginx.ingress.kubernetes.io/server-snippet: |
      proxy_ssl_name externaldomain.com;
      proxy_ssl_server_name on;
spec:
  ingressClassName: nginx
  rules:
  - host: myingress.com
    http:
      paths:
        - pathType: Prefix
          backend:
            service:
              name: api-proxy
              port:
                number: 80
          path: /

CodePudding user response:

According to the documentation setting proxy_redirect annotations should do the trick: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#proxy-redirect

  • Related