I have two domain names, each for different applications hosted in a single kubernetes cluster.
Is there a way to configure ingress to redirect to the different apps based on the hostname in the request it receives?
For example:
www.app1.com
and www.app2.com
point to the same IP address. However, I want www.app1.com
to redirect to /appABC
while www.app2.com redirect to /appXYZ
.
I have attempted to capture the host name and use this to determine the redirect but it doesn’t work.
Is what I’m trying to do possible with NGINX?
2
Answers
After some experimentation, using the NGINX Playground, I was able to come up with this solution.
In case you're wondering why a number of
if statement
s had to be used this way, NGINX is not that great with if statements and logical operations.Another caveat worth stating here is that all ingresses associated with this NGINX controller will be affected by this
server-snippet
; Becausenginx.ingress.kubernetes.io/server-snippet
is a global annotation.Yes,it is Possible. You must need to create two configuration files and point them to their respective paths. Please follow this link for more info and refer to this SO also to get further idea on how to use.