Kibana4 + nginx reverse proxy using location /kibana4/ = Not Found 404

Solution 1:

Thank you HD. for your question below my previous post - it was very enlightening. It helped me realize what was the problem. I always forget that location part is also passed to proxy, that's why it has to be rewritten in my case. Here is what the correct config should look like:

  location ~ ^/kibana4/(.*)$ {
    rewrite /kibana4/(.*) /$1  break;
    proxy_pass              http://$kibana:5601;
    proxy_set_header        Host $host;
    proxy_set_header        Referer "";
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version      1.1;
    proxy_connect_timeout   150;
    proxy_send_timeout      100;
    proxy_read_timeout      100;
    proxy_buffers           16 64k;
    proxy_busy_buffers_size 64k;
    client_max_body_size    256k;
    client_body_buffer_size 128k;
  }

It also explains why the location / setting is working correctly if there is no rewrite part. After adding rewrite, only the rest part is passed to proxy and it works like a charm.

Thank you once again, lesson learned :-)

Solution 2:

Late to the party, but I wanted to leave a satisfactory solution for Apache here since I can't find them. The thing that made proxying from a subdirectory for me work was adding a trailing slash after the ProxyPass directory:

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

See here:

http://www.marathon-studios.com/blog/solved-kibana-5-not-loading-404ing-when-reverse-proxying-in-a-subdirectory/