Redirect Nginx Ingress Controller Requests to External Domain

i have an nginx ingress controller and i would like to redirect whatever requests coming in to an external domain, i.e, i dont have a service hosted for it in my cluster. Is it possible to do it? I tried below with an non existent service, but it did not work

apiVersion: 
kind: Ingress
metadata:
  name: external-redirect
  annotations:
     |
      rewrite ^/$  permanent;
spec:
  rules:
    - host: your.domain.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: non-existent-service
                port:
                  number: 80
3

1 Answer

Instead of using rewrite we have an annotation . Which will permanently redirect (Return Code 301) instead of sending data to the upstream. For example will redirect everything to an example.com .

Similarly annotation also redirects temporarily, which allows you to return a temporal redirect (Return Code 302) instead of sending data to the upstream.

Use below example permanent annotations :

/

Refer to Github link for more information.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest