<p>So I have an interesting use case. I am running multiple micro-services on my Kubernetes cluster. My applications use NextJS which make internal calls to _next routes.</p>

<p>My issue came from the fact that I needed a way to differentiate between services and their requests to the _next files. So I implemented NextJS's assetPrefix feature which works perfectly in development, appending my prefix in front of _next so the requests look like <code>.../${PREFIX}/_next/...</code>. That way I could set up an ingress and route files base on the prefix to the appropriate service on my cluster. I set up a Kubernetes Ingress controller following this guide: <a href="https://akomljen.com/kubernetes-nginx-ingress-controller/" rel="nofollow noreferrer">https://akomljen.com/kubernetes-nginx-ingress-controller/</a></p>

<p>My ingress config is: </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: dev-ingress
spec:
  rules:
  - host: baseurl.com
    http:
      paths:
      - path: /auth
        backend:
          serviceName: auth-svc
          servicePort: 80
      - path: /static/auth
        backend:
          serviceName: auth-svc
          servicePort: 80
      - path: /login
        backend:
          serviceName: auth-svc
          servicePort: 80
      - path: /settings
        backend:
          serviceName: auth-svc
          servicePort: 80
      - path: /artwork
        backend:
          serviceName: artwork-svc
          servicePort: 80
      - path: /static/artwork
        backend:
          serviceName: artwork-svc
          servicePort: 80
</code></pre>

<p>So here is the problem. Now that everything is set up, properly deployed, and the ingress is running following the above guide and using the above rules, my services are trying to make requests to <code>.../_next/...</code> instead of  <code>.../${PREFIX}/_next/...</code> so they can't find the proper files and nothing is working. I cannot seem to figure out what is going on. Anyone have any ideas? Thanks in advance!</p>

L. Norman
<p>You are using built-in NGINX Ingress Controller that, unfortunately, has no such functionality.</p>

<p>My advice is to use <a href="https://github.com/nginxinc/kubernetes-ingress" rel="nofollow noreferrer">NGINX Plus Ingress Controller</a> annotation functionality if you can afford it.</p>

<p>You can find <a href="https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/rewrites" rel="nofollow noreferrer">official  example here</a>.</p>

<p>Example:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
  annotations:
    nginx.org/rewrites: "serviceName=tea-svc rewrite=/;serviceName=coffee-svc rewrite=/beans/"
spec:
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea/
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee/
        backend:
          serviceName: coffee-svc
          servicePort: 80
</code></pre>

<p>Below are the examples of how the URI of requests to the  <code>tea-svc</code>  are rewritten (Note that the  <code>/tea</code>  requests are redirected to  <code>/tea/</code>).</p>

<pre><code>/tea/  -&gt;  /
/tea/abc  -&gt;  /abc
</code></pre>

<p>Below are the examples of how the URI of requests to the  <code>coffee-svc</code>  are rewritten (Note that the  <code>/coffee</code>  requests are redirected to  <code>/coffee/</code>).</p>

<pre><code>/coffee/  -&gt;  /beans/
/coffee/abc  -&gt;  /beans/abc
</code></pre>
