Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Kibana 4 and elasticsearch behind nginx?

I have kibana 4 and elasticsearch running on the same server.

I need to access kibana through a domain but when I try I keep getting file not found.

I just create location /kibana in nginx and the proxy_pass is the ip:port of kibana.
Anyone had this?

like image 412
Ayman Al-Shorman Avatar asked Mar 10 '15 02:03

Ayman Al-Shorman


4 Answers

This workd for kibana 4.0.1. and I assume that you run kibana on the same host as nginx listening to port 5601.

Your nginx config should look like:

server {
  listen                *:80 ;

  server_name           server;
  access_log            /var/log/nginx/kibana.srv-log-dev.log;
  error_log            /var/log/nginx/kibana.srv-log-dev.error.log;

  location / {
    root  /var/www/kibana;
    index  index.html  index.htm;
  }

  location ~ ^/kibana4/.* {
    proxy_pass http://kibana4host:5601;
    rewrite ^/kibana4/(.*) /$1 break;
    proxy_set_header Host $host;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/conf.d/kibana.myhost.org.htpasswd;
  }
}

The lines

auth_basic "Restricted";
auth_basic_user_file /etc/nginx/conf.d/kibana.myhost.org.htpasswd;

can be used so that you provide a basic authentication to the site.

The access link will be http://server/kibana4

like image 73
psebos Avatar answered Nov 17 '22 12:11

psebos


don't just use location because its looking for an actual file after the /

kibana4 is not location based but an actual service

whenever you use proxy_pass you must use upstream deceleration with it

here's a working config with http basic auth, and SSL termination

upstream kibana {
    server 127.0.0.1:5601 fail_timeout=0;
}

server {
    listen      80;
    return 301 https://example.com;
}

server {
  listen                *:443 ;
  ssl on;
  ssl_certificate /etc/nginx/ssl/all.crt;
  ssl_certificate_key /etc/nginx/ssl/server.key;

  server_name           example.com;
  access_log            /var/log/nginx/kibana.access.log;

  location / {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/conf.d/kibana.htpasswd;
    proxy_pass http://kibana;
  }
}
like image 40
Ami Mahloof Avatar answered Nov 17 '22 12:11

Ami Mahloof


this worked for me with Kibana 4.6.1:

location ~ (/app/kibana|/bundles/|/kibana|/status|/plugins) {
    proxy_pass http://localhost:5601;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    rewrite /kibana/(.*)$ /$1 break;
}

(from here)

Not quite an elegant solution, but still..

NB: server.basePath in Kibana config has to be set as "/" (or commented at all) in this case

like image 21
62mkv Avatar answered Nov 17 '22 13:11

62mkv


I fixed it by the following:

location /kibana4/ {
proxy_pass http://host:5601/;
proxy_redirect http://host:5601/ /kibana4/;
}

I had to use proxy_redirect to have the response back !

Thanks

like image 3
Ayman Al-Shorman Avatar answered Nov 17 '22 11:11

Ayman Al-Shorman