Forum Discussion
How to rewrite a path to a backend service dropping the prefix and passing the remaining path?
Hello xuwen & JRahm,
Thank you fo your quick responses and help. After a break, I adjusted the path, as below, and was able to successfully route to httpbin and preserve the path after the prefix. Hopefully, this will help others... 🙂
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mikie-ingress
namespace: mikie
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
ingressClassName: nginx
rules:
- host: abczzz.com
http:
paths:
- backend:
service:
name: httpbin-service
port:
number: 8999
path: /httpbin/(.*)
pathType: Prefix
- michaelgardnerJun 03, 2022Altocumulus
In order to compare my issues, I deployed nginx-ingress, which we will be using for our deployment, and the community edition, to two separate Kubernetes clusters. When I reported success a few minutes ago, it was with the community edition. However, with nginx-ingress and the same manifests used for the community edition, the rewrites are not succeeding... 404s... Arggg...
I've attached my deployment scripts, which I was documenting for our team. Could you please take a look at them to see whether you spot any reasons that they wouldn't work, as expected? I am going to dig back in when I get back into the office in the morning and will report what I find. I've left the httpbin backend services running, in case you want to play with anything. No issues with your access, if desired.
Thank you for your help and support,
Mike
- JRahmJun 03, 2022Admin
I'll try to track down some help for you, michaelgardner. In the meantime, can you clarify if you are using the kuburnetes flavor of nginx ingress, or the nginx ingress for kubernetes? Clear as mud, I know...this might help: https://www.nginx.com/blog/guide-to-choosing-ingress-controller-part-4-nginx-ingress-controller-options/.
Examples of rewrites from the nginx ingress BY nginx: https://github.com/nginxinc/kubernetes-ingress/tree/v2.2.2/examples/rewrites- JRahmJun 03, 2022Admin
ok, maybe you're using the kubernetes version of the nginx ingress instead of the nginx version of the nginx ingress. Give a read-through on that article I linked and take a look at the examples. Not telling you which version to use, but the expertise around here will be more geared toward the nginx version.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com