kibana server.basePath results in 404

Nathan Reese picture Nathan Reese · Mar 28, 2016 · Viewed 9.6k times · Source

I am running kibana 4.4.1 on RHEL 7.2

Everything works when the kibana.yml file does not contain the setting server.basePath. Kibana successfully starts and spits out the message

[info][listening] Server running at http://x.x.x.x:5601/

curl http://x.x.x.x:5601/app/kibana returns the expected HTML.

However, when basePath is set to server.basePath: "/kibana4", http://x.x.x.x:5601/kibana4/app/kibana results in a 404. Why?

The server successfully starts with the same logging

[info][listening] Server running at http://x.x.x.x:5601/

but

curl http://x.x.x.x:5601/ returns

<script>
  var hashRoute = '/kibana4/app/kibana';
  var defaultRoute = '/kibana4/app/kibana';
  ...
</script>

curl http://x.x.x.x:5601/kibana4/app/kibana returns {"statusCode":404,"error":"Not Found"}

Why does '/kibana4/app/kibana' return a 404?

Answer

Nathan Reese picture Nathan Reese · Mar 29, 2016

server.basePath does not behave as I expected.

I was expecting server.basePath to symmetrically affect the URL. Meaning that request URLs would be under the subdomain /kibana4 and response URLs would also be under the subdomain /kibana4.

This is not the case. server.basePath asymetrically affects the URL. Meaning that all request URLs remain the same but response URLs have included the subdomin. For example, the kibana home page is still accessed at http://x.x.x.x:5601/app/kibana but all hrefs URLs include the subdomain /kibana4.

server.basePath only works if you use a proxy that removes the subdomain before forwarding requests to kibana

Below is the HAProxy configuration that I used

frontend main *:80
   acl url_kibana   path_beg   -i /kibana4
   use_backend kibana   if url_kibana

backend kibana
   mode http
   reqrep ^([^\ ]*)\ /kibana4[/]?(.*) \1\ /\2\
   server x.x.x.x:5601

The important bit is the reqrep expression that removes the subdomain /kibana4 from the URL before forwarding the request to kibana.