4

I'm trying to setup Kibana4 with nginx reverse proxy, with partial success so far. Here is my config related to Kibana:

server {
  listen 82;
  server_name ${HOSTNAME};

  set $kibana kibana.docker;

  location /kibana4/ {
    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;
  }
}

In that case if I go to http://localhost:82/kibana4/ I will get Not Found 404

But if I replace location /kibana4/ with location /, everything work well - of course URL changes to http://localhost:82 in that case.

I have found a few other topics related to similar problem, e.g.:

Running sinatra program [Kibana] behind nginx reverse proxy in web directory

but the solutions described there don't work for me. I even tried this config:

server {
  listen 82;
  server_name ${HOSTNAME};

  set $kibana kibana.docker;

  location /kibana4 {
    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 starts proxy to kibana.docker host, but the problem is that all URL are rewritten to the same kibana loading page. It causes that any CSS or JavaScript file cannot be loaded properly.

My question is: does anyone know what can be wrong here? Does anyone run successfully Kibana4 from a different than server root location? I would appreciate your help.

2

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 :-)

1

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/

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.