<p>I have a Kibana dashboard that I currently access through the root of my host : <code>https://my.host.com/</code>. I want to change it so I can access it through the path <code>https://my.host.com/kibana/</code>. For this, I used the <code>rewrite-target</code> annotation as provided in the <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">main documentation</a>:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: kibana-ing
  annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /$2
      kubernetes.io/ingress.class: kibana-ingress-class
      nginx.ingress.kubernetes.io/backend-protocol: &quot;HTTPS&quot;
spec:
  rules:
    - host: my.host.com
      http:
        paths:
          - path: /kibana(/|$)(.*)
            backend:
              serviceName: kibana-svc
              servicePort: 5601
</code></pre>
<p>I think this works to some extent because when hitting <a href="https://my.host.com/kibana/" rel="nofollow noreferrer">https://my.host.com/kibana/</a>, I get redirected to the login page. But the login page is returned to my browser without the kibana prefix : <code>https://my.host.com/app/login</code> and I get a 404.</p>
<p>How can I fix this?</p>
<p><strong>EDIT:</strong></p>
<p>This is currently what is happening when I hit <code>https://my.host.com/kibana/</code> :</p>
<p><a href="https://i.stack.imgur.com/mr9Z3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mr9Z3.png" alt="enter image description here" /></a></p>
<p>This sends back a HTTP 302 with a redirection to <code>app/login</code> as you can see in the <strong>Location</strong> header. But when my browser asks back Nginx to fetch for this app/login, it rightfully gives a 404 since this path is unkown to it.</p>
<p>Is there a way (through an Ingress annotation maybe) to append the '/kibana' prefix to all the <strong>Location</strong> headers that are being returned?</p>
<p><strong>EDIT2:</strong></p>
<p>I managed to append the <code>/kibana/</code> part in the <strong>Location</strong> header by adding these 2 annotations:</p>
<pre><code>nginx.ingress.kubernetes.io/proxy-redirect-from: &quot;/&quot;
nginx.ingress.kubernetes.io/proxy-redirect-to: &quot;/kibana/&quot;
</code></pre>
<p>This makes the redirection point to <code>kibana/app/login</code>, resulting in a 200 status. However more objects are being loaded by the page like a bootsrap.js and their location are hardcoded within the html page being sent back like this:</p>
<pre><code>&lt;/script&gt;&lt;script src=&quot;/bootstrap.js&quot;&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
</code></pre>
<p>Obviously this hits back with another 404 error on my browser end... I think I will have to deal with this on the application end instead.</p>

<p>I managed to fix this at the application level. In my <code>kibana.yml</code> config file, I had to tell Kibana that it was running behind a reverse proxy. So I set <code>server.basePath: /kibana</code>.</p>
<p>Note that the configuration I made above for the Ingress is still needed, as the application is still reacheable at the root of server but only the responses URLs will include the <code>/kibana/</code> prefix.</p>
