Kubernetes ingress-nginx rewrite without changing browser url
With this solution as a reference, pointed out by @WytrzymaĆyWiktor I was able to make changes and it worked.Here is the updated ingress file.
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: annotations: nginx.ingress.kubernetes.io/server-snippet: | location ~ "^/(.*)" { proxy_pass http://example.xyz.com; rewrite /(.*)$ /$1 break; } name: url-rewrite namespace: defaultspec: rules: - host: site.abc.com
One problem though here in making SSL redirect work. In some cases the target(http://example.xyz.com) will return 302 /some/other/path
in such cases http://site.abc.com gets redirected as http://site.abc.com/some/other/path. Not sure how to make it to redirect as https://site.abc.com/some/other/path.Setting nginx.ingress.kubernetes.io/ssl-redirect: "true"
and nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
doesn't seem to work.
Adding this as an answer for documentation, As it will be helpful for people with a similar problem. Not a possible duplicate as the referenced solution addresses on adding proxy_pass
whereas this, addresses URL rewrite without changing browser URL.