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

Any reason for adding slash after target path for rewrite-target annotation? #3148

Open
ZxYuan opened this Issue Sep 27, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@ZxYuan
Copy link

ZxYuan commented Sep 27, 2018

What keywords did you search in NGINX Ingress controller issues before filing this one? (If you have found any duplicates, you should instead reply there.):

rewrite-target annotation, proxy_pass


NGINX Ingress controller version:
0.19.0

Kubernetes version (use kubectl version):
1.8.5

Environment:

  • Cloud provider or hardware configuration:
    hardware
  • OS (e.g. from /etc/os-release):
    centos 6
  • Kernel (e.g. uname -a):
    3.10.0_3-1-0-3

What happened:

I have an ingress resource yaml as below. I would like to receive the response from http://host:port/cat when visiting http://host:port/dog, but got HTTP 404 from upstream service of nginx.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-api-test
  annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /cat
spec:
  rules:
  - host: x.x.x.x
    http:
      paths:
      - path: /dog
        backend:
          serviceName: service-model-test
          servicePort: 80

After I checked the generated nginx.conf inside pod, I found the location configuration as below.

location ~* ^/dog\/?(?<baseuri>.*) {
        ......
        rewrite (?i)/dog/(.*) /cat/$1 break;
        rewrite (?i)/dog$ /cat/ break;
        ......
}

I wonder if the slash after cat of rewrite (?i)/dog$ /cat/ break; is necessary. In this way, any target path ends without slash cannot be matched.

What you expected to happen:

No slash after cat: rewrite (?i)/dog$ /cat break;

How to reproduce it (as minimally and precisely as possible):

Refer to the ingress yaml above

Anything else we need to know:

@hipyhop

This comment has been minimized.

Copy link

hipyhop commented Oct 18, 2018

This is affecting us too.

We have some backend services that don't support a trailing slash on paths and we want to make a direct path mapping. For example: /ping/service/foo -> /ping

but the generated nginx configuration rewrites it to: /ping/

Until this is fixed this can be worked around using a configuration-snippet

nginx.ingress.kubernetes.io/configuration-snippet: |
    rewrite (?i)/ping/service/foo$ /ping break;
@ZxYuan

This comment has been minimized.

Copy link

ZxYuan commented Oct 19, 2018

This is affecting us too.

We have some backend services that don't support a trailing slash on paths and we want to make a direct path mapping. For example: /ping/service/foo -> /ping

but the generated nginx configuration rewrites it to: /ping/

Until this is fixed this can be worked around using a configuration-snippet

nginx.ingress.kubernetes.io/configuration-snippet: |
    rewrite (?i)/ping/service/foo$ /ping break;

Nice solution

@AlexLast

This comment has been minimized.

Copy link

AlexLast commented Dec 13, 2018

This is affecting us too.

We have some backend services that don't support a trailing slash on paths and we want to make a direct path mapping. For example: /ping/service/foo -> /ping

but the generated nginx configuration rewrites it to: /ping/

Until this is fixed this can be worked around using a configuration-snippet

nginx.ingress.kubernetes.io/configuration-snippet: |
    rewrite (?i)/ping/service/foo$ /ping break;

This solution worked for us 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment