I'm trying to rewrite the path to the service while preserving the browser url with nginx ingress on kubernetes.
What I need is this:
http://example.com/path
=>http://service
http://example.com/path/bar
=>http://service/bar
http://example.com/path/file.css
=>http://service/file.css
That is, make the /path
be the root (or some different url) in the upstream server.
From what I see here, this is done using a trailing slash on the proxy_pass, but nginx ingress doesn't seem to have this option.
Is this possible nginx ingress?
Yes, In order to achieve it you can use
rewrite-target
.It will create a capture group and send it to the appropriate service. Here is an Ingress example:
This ingress will do the following:
Example:
If you have any question let me know in the comments.
In short: yes it is. Make sure not to confuse nginx-ingress (which you use as a label in your question ) and ingress-nginx, those are different. It works with ingress-nginx by installing it according to documentation. The provided answer from @Will R.O.F. shows how and the documentation can be found here: https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/