-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[nginx] Redirect with added trailing slash #646
Comments
Related: kubernetes-retired/contrib#1884 As a workaround
This works with
|
Issues go stale after 90d of inactivity. Prevent issues from auto-closing with an If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Further to what @rutsky mentioned in his comment if you are using nginx ingress controller specifically and your annotations start with nginx as follows:
Your annotation should start with |
Please keep in mind that while @ProProgrammer 's solution works 301 redirects are PERMANENT. The unintended byproducts of forcing a trailing slash via 301 can be enough to get you fired. It's likely safer to start with a 302 temporal redirect if you're just futzing around trying to get something operational. Per the NGINX docs you can use the
|
I can't quite get that rewrite rule/block to work. It redirects me to the (internal) load balancer IP. Is there another config to explicitly set the host? nginx doesn't work if I specify the host (there's an internal load balancer), I think the DNS name is getting dropped from the public load balancer. |
for anyone who's checking this issue, the annotation is now changed to |
If you are wondering how |
Nginx by default automatically adds HTTP redirect
/foo -> /foo/
when using prefix match with trailing slashlocation /foo/
which is redirected to a backend (documented in the last paragraph here). This behavior is useful when serving a web application at http://example.com/foo/ and a user accesses http://example.com/foo. Unfortunately, this behavior is broken when usingingress.kubernetes.io/rewrite-target
annotation, which turns location match into a non-prefix regex one.I would argue that the behavior of adding a trailing slash by HTTP redirect on the base path of an web application exposed through an non-root Ingress (with or without a rewrite target) is very useful and should either work by default, or be enabled via some separate annotation.
I was unable to find a workaround in the latest version of Nginx ingress controller. Using
/foo
ingress path does not work as it breaks relative links inside the web application.Also, if #619 would be fixed by unconditionally enabling regular expressions, even the currently working cases (without rewrite) will break.
The text was updated successfully, but these errors were encountered: