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 Don't Have a Service Hosted for It...
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
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.