<p>I have a ReactJS front end, Spring boot backend app deployed on a baremetal Kubernetes cluster which is running Kubernetes Ingress and requests are proxied to it by HAProxy. When visiting the URL of the app, I can see it loads the index.html of the app but all other requests to static assets are not done properly.</p>

<p>The ingress resource of my app:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: app
name: app-ingress
annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$3
spec:
rules:
- host: devops
    http:
    paths:
    - path: /dev/app1(/|$)(.*)
        backend:
        serviceName: app1
        servicePort: 80
</code></pre>

<p>When inspecting the page which loads using Chrome Developer tools, I see that there are 6 outgoing calls to the static assets. The call that retrieves the <code>index.html</code> of the app completes succesfully but the calls that retrieve the static assets (ex: <code>http://devops/dev/app1/static/js/4.2761693d.chunk.js</code>) does not work properly as it retrieves the <code>index.html</code> page as well. (only the <code>index.html</code> page is served by all calls basically)</p>

<p>I had a feeling it is because of the <code>nginx.ingress.kubernetes.io/rewrite-target</code> annotation but removing it causes a 404 even on the <code>index.html</code> page.</p>

<p>I am using nginx ingress controller 0.25.1</p>

<p>EDIT:</p>

<p>This is the output when I exec into the container and run <code>curl localhost:8080/dev/app1/static/js/4.2761693d.chunk.js</code> (error fallback page)</p>

<p><a href="https://i.stack.imgur.com/nhYVU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nhYVU.png" alt="enter image description here"></a></p>

<p>This is the output when I run <code>curl localhost:8080/tatic/js/4.2761693d.chunk.js</code> (correctly loads the css)</p>

<p><a href="https://i.stack.imgur.com/1sJKu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1sJKu.png" alt="enter image description here"></a></p>

<p>Somehow, when I change the rewrite annotation to this, it works:</p>

<p><code>nginx.ingress.kubernetes.io/rewrite-target: /$2</code></p>

<p>I didnt change anything else.</p>

<p>Now the application is accessible at <code>devops/dev/app1/</code> (but it does not work without the <code>/</code> at the end)</p>

<p>I am not sure how this works. I had no logic behind it, I was just changing values in the ingress file to see if anything works.</p>

<p>Can someone explain why it works?</p>
