Reverse proxying Kibana with Nginx at a subpath (/kibana)

Reverse proxying to Kibana when its hosted at root path (/) i.e https://kibana.tools.example.org/ works out-of-the-box. Problem is, most folks don’t have a dedicated certificate for each internal application. Instead, the common practice is to host apps via a subpath such as https://tools.example.org/kibana/. This is where things get tricky. Kibana supports a config variable called server.basePath that is supposed to set its base path so that all emitted links are prefix accordingly. This is supposed to make Kibana play nice when it behind a reverse proxy. As of today, the latest version still has issues ( #5171, #1555 and #6339)

Assuming you have kibana running on default port 5601, server.basePath set to “” and Nginx is configured to respond to hostname tools.example.org, the following Nginx configuration make Kibana play nice at subpath /kibana and /kibana/


-- snip --

# kibana is actually hosted at /app/kibana
# This redirect points it to the right direction
location = /kibana {
  return 301 https://tools.example.org/app/kibana;
}

location = /kibana/ {
  return 301 https://tools.example.org/app/kibana;
}

# by default Kibana redirects /app/kibana/ to /app/kibana
location = /app/kibana/ {
  return 301 https://tools.example.org/app/kibana;
}

# this is where the app is served
location = /app/kibana {
  proxy_pass http://kibana-host:5601;
}

# internal application links
location /app/kibana/ {
  proxy_pass http://kibana-host:5601;
}

# static content is not relative to /app/kibana. 
# instead its served at /bundles/*
# see https://github.com/elastic/kibana/issues/6339
location /bundles/ {
  proxy_pass http://kibana-host:5601;
}

# 
-- snip --