How to configure Kibana 4 and elasticsearch behind nginx?

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


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;
  }
}

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