[SOLVED]: Kibana 5 not loading / 404ing when reverse-proxying in a subdirectory

I just solved an issue with Kibana 5 that many, many people seem to have experienced while trying to install the log analysis app in a subdirectory.

Because Kibana is insecure by default (something I hate about the otherwise-wonderful products made by Elastic), most sysadmins choose to install it locked to localhost only, and allow access by setting up a reverse-proxy using Apache or Nginx.

While many people reverse-proxy Kibana to the root directory of their server and have no issues, I wanted to put it in a subdirectory, /kibana, because I am running multiple services with web interfaces (like phpMyAdmin, etc) on the same server.

After adding /kibana as the basePath in /etc/kibana/kibana.yml, I added the following code to set up the reverse-proxy:


# Kibana Reverse Proxy
ProxyRequests On
ProxyPreserveHost On

ProxyPass /kibana http://localhost:5601/
ProxyPassReverse /kibana http://localhost:5601/


## Auth
AuthType Basic
AuthName "Kibana"
AuthUserFile /var/www/.htpasswd
Require valid-user

When I did this, I got a JSON output with a 404. Another post I saw suggested adding /app/kibana to the proxy rewrite location, however this yielded the error “Kibana did not load properly. Check the server output for more information.” A check of the web console showed that Kibana was trying to load resources from /kibana/bundles, which were 404ing.

The forums and even StackOverflow were full of people who had this problem, and no solutions. However, I finally found one: the rewriting issues are being caused because of a missing slash after /kibana in my proxy configuration. Change to this, and it all works:


ProxyPass /kibana/ http://localhost:5601/
ProxyPassReverse /kibana/ http://localhost:5601/

For good measure, I also added a redirect:


# Add stupid trailing slash that makes Kibana proxy work
RewriteCond %{REQUEST_URI} ^/kibana$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [R=301,L]

Hopefully this saved you some time.

Leave a Reply

Your email address will not be published. Required fields are marked *