Ayman Al-Shorman
Ayman Al-Shorman

Reputation: 300

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?

Upvotes: 8

Views: 32164

Answers (5)

VvanGemert
VvanGemert

Reputation: 1

As Kibana has a separate front- and backend. You'll need to setup two proxies for both sides. This worked for me in Kibana 7+ with no changes to the Kibana config file :

set $proxy_pass_url http://localhost:5601;

# Main location which proxy's Kibana backend server
location / {
    proxy_set_header Host $proxy_pass_url;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_http_version 1.1;
    proxy_set_header Connection "Keep-Alive";
    proxy_set_header Proxy-Connection "Keep-Alive";
    proxy_set_header Authorization "";
    proxy_pass $proxy_pass_url/;
    proxy_redirect $proxy_pass_url/ /;
}

# Reverse proxy of assets and front end app
location ~ (/app|/translations|/node_modules|/built_assets/|/bundles|/es_admin|/plugins|/api|/ui|/elasticsearch) {
    proxy_pass          $proxy_pass_url;
    proxy_set_header    Host $host;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto $scheme;
    proxy_set_header    X-Forwarded-Host $http_host;
    proxy_set_header    Authorization "";
    proxy_hide_header   Authorization;
}

Upvotes: 0

62mkv
62mkv

Reputation: 1522

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

Upvotes: 5

Ayman Al-Shorman
Ayman Al-Shorman

Reputation: 300

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

Upvotes: 3

Ami Mahloof
Ami Mahloof

Reputation: 472

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

Upvotes: 6

psebos
psebos

Reputation: 509

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

Upvotes: 16

Related Questions