<p>I have 3 ingress rules in a cluster that point to 3 different services/deployments.</p>
<p>I want each app, which is configured to listen on <code>/tenant</code> to respond to their respective sub path, so:</p>
<p><a href="https://example.com/foo" rel="nofollow noreferrer">https://example.com/foo</a> -&gt; foo service
<a href="https://example.com/bar" rel="nofollow noreferrer">https://example.com/bar</a> -&gt; bar service</p>
<p>and so on</p>
<p>The ingress rule for foo looks like this.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    meta.helm.sh/release-name: foo-platform
    meta.helm.sh/release-namespace: aks-foo-namespace
    nginx.ingress.kubernetes.io/client-header-buffer-size: 64k
    nginx.ingress.kubernetes.io/client_body_buffer_size: 64k
    nginx.ingress.kubernetes.io/http2-max-field-size: 16k
    nginx.ingress.kubernetes.io/http2-max-header-size: 128k
    nginx.ingress.kubernetes.io/large-client-header-buffers: 8 64k
    nginx.ingress.kubernetes.io/proxy-body-size: &quot;0&quot;
    nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
    nginx.ingress.kubernetes.io/proxy-buffers: 4 256k
    nginx.ingress.kubernetes.io/proxy-busy-buffers-size: 256k
  labels:
    app.kubernetes.io/managed-by: Helm
  name: foo-ingress
  namespace: foo
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          service:
            name: foo-service
            port:
              number: 80
        path: /foo1/(.*)
        pathType: Prefix
  tls:
  - hosts:
    - example.com
    secretName: example-tls-ingress
</code></pre>
<p>Now, this currently works, but <em>only</em> if another, unrelated namespace is configured like this:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    meta.helm.sh/release-name: bar-platform
    meta.helm.sh/release-namespace: aks-bar-namespace
    nginx.ingress.kubernetes.io/client-header-buffer-size: 64k
    nginx.ingress.kubernetes.io/client_body_buffer_size: 64k
    nginx.ingress.kubernetes.io/http2-max-field-size: 16k
    nginx.ingress.kubernetes.io/http2-max-header-size: 128k
    nginx.ingress.kubernetes.io/large-client-header-buffers: 8 64k
    nginx.ingress.kubernetes.io/proxy-body-size: &quot;0&quot;
    nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
    nginx.ingress.kubernetes.io/proxy-buffers: 4 256k
    nginx.ingress.kubernetes.io/proxy-busy-buffers-size: 256k
    nginx.ingress.kubernetes.io/rewrite-target: $1
  labels:
    app.kubernetes.io/managed-by: Helm
  name: bar-ingress
  namespace: bar
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          service:
            name: bar-service
            port:
              number: 80
        path: /bar/(.*)
        pathType: Prefix
  tls:
  - hosts:
    - example.com
    secretName: bar-tls-ingress
</code></pre>
<p>Notice the <code>rewrite-target</code> annotation which appears to <em>need</em> to be there. Unfortunately, this means that <a href="https://example.com/bar" rel="nofollow noreferrer">https://example.com/bar</a> doesn't respond correctly, and is configured on <a href="https://example.com/bar/bar" rel="nofollow noreferrer">https://example.com/bar/bar</a></p>
<p>I looked at the <code>nginx.conf</code> for a working foo ingress, and noticed the location block is wildly different if the <code>rewrite-target</code> annotations is present. When it's broken, the <code>location</code> block is set to <code>location ~*</code> so something isn't right.</p>
<p>What's the right way to configure subpaths for nginx-ingress? How can I make all 3 apps respond on <a href="https://example.com/app-tenant-name" rel="nofollow noreferrer">https://example.com/app-tenant-name</a></p>

jaxxstorm
<p>ideally, this should not be the case, Nginx won't be crashing or so. i would suggest updating the <strong>path</strong> and <strong>re-write</strong> annotation a little bit and check</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    meta.helm.sh/release-name: bar-platform
    meta.helm.sh/release-namespace: aks-bar-namespace
    nginx.ingress.kubernetes.io/client-header-buffer-size: 64k
    nginx.ingress.kubernetes.io/client_body_buffer_size: 64k
    nginx.ingress.kubernetes.io/http2-max-field-size: 16k
    nginx.ingress.kubernetes.io/http2-max-header-size: 128k
    nginx.ingress.kubernetes.io/large-client-header-buffers: 8 64k
    nginx.ingress.kubernetes.io/proxy-body-size: &quot;0&quot;
    nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
    nginx.ingress.kubernetes.io/proxy-buffers: 4 256k
    nginx.ingress.kubernetes.io/proxy-busy-buffers-size: 256k
    nginx.ingress.kubernetes.io/rewrite-target: $2
  labels:
    app.kubernetes.io/managed-by: Helm
  name: bar-ingress
  namespace: bar
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          service:
            name: bar-service
            port:
              number: 80
        path: /bar(/|$)(.*)
        pathType: Prefix
  tls:
  - hosts:
    - example.com
    secretName: bar-tls-ingress
</code></pre>
<p>updated the <code>nginx.ingress.kubernetes.io/rewrite-target: $2</code> &amp; path changes for <strong>bar</strong> service.</p>
