<p>I have ingress service with the fallowing config:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          - path: /api/?(.*)
            backend:
              serviceName: my-service
              servicePort: 3001
          - path: /auth/?(.*)
            backend:
              serviceName: my-service
              servicePort: 3001
</code></pre>

<p>The thing is that when I'm running this on my minikube I cannot connect in a proper way, ie.
When I'm typing in the browser: <code>IP/api/test</code> it shows <code>not found</code> even though my express endpoint is:</p>

<pre><code>app.get('/api/test', (req, res) =&gt; {
  return res.send({ hi: 'there' });
});
</code></pre>

<p>But <code>IP/api/api/test</code> (double <code>api</code>) works and delivers expected response. Obviously I would like to get there with <code>IP/api/test</code>. How can I achieve that in my ingress config?</p>

Murakami
<p>If You want to access <code>http://.../api/test</code> by calling curl <code>http://.../api/test</code> than you don't need a rewrite for it so just make it empty.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          - path: /?(.*)
            backend:
              serviceName: my-service
              servicePort: 3001
          - path: /auth/?(.*)
            backend:
              serviceName: my-service
              servicePort: 3001
</code></pre>

<p>This configuration will for example rewrite the following:</p>

<pre><code>http://.../api/test -&gt; http://.../api/test
</code></pre>

<pre><code>http://.../auth/test -&gt; http://.../test
</code></pre>

<pre><code>http://.../asdasdasd -&gt; http://.../asdasdasd
</code></pre>

<hr>

<p>Update:</p>

<p>In case You have another rewrite with <code>path: /?(.*)</code> You can modify Your app path request to:</p>

<pre><code>app.get('/test', (req, res) =&gt; {
  return res.send({ hi: 'there' });
});
</code></pre>

<p>and use the original ingress configuration You posted in Your question.</p>

<p>This way when the request You have issues with will be resolved in following way:</p>

<p><code>IP/api/test</code> -> <code>IP/test</code></p>

<p>This is also the reason why You experienced <code>IP/api/api/test</code> before. Because one <code>/api/</code> was removed by rewrite and then <code>IP/api/test</code> was accessible.</p>

<p>Yes, You can have multiple rewrites in ingress. As long as they don't loop or rewrite too many times.</p>
