server.basePath in version 5.2.2

Hello there,

Unfortunately, we are still running kibana in version 5.2.2. and we need to modify the server.basePath for multiple servers.

Here is our kibana.yml:

server.basePath: "/abc"

I know we have to rewrite the basePath in our proxy, https://github.com/elastic/kibana/issues/6665
so in our nginx, we have these blocks:

location = / {
  rewrite ^/abc /abc/app/kibana;
  proxy_pass http://127.0.0.1:5601;
  proxy_read_timeout 90;
}

location = /abc {
  rewrite ^/abc /abc/app/kibana;
  proxy_pass http://127.0.0.1:5601;
  proxy_read_timeout 90;
}

location /abc {
  rewrite ^/abc/(.*)$ /$1 break;
  proxy_pass http://127.0.0.1:5601;
  proxy_read_timeout 90;
}

The confusion I have is that:

  1. I know if we hit the url like this: http://xxx.xxx.com/abc without rewriting it, I will get a 404. That means I had to rewrite it. But will server.basePath be appended when I hit http://xxx.xxx.com automatically just because I have it in kibana.yml, will the url sent to the nginx transformed to: http://xxx.xxx.com/abc ?

  2. If server.basePath doesn't get appended to http://xxx.xxx.com, then that means http://xxx.xxx.com will go to the first the location block in nginx. But the rewrite rule in my first location block in nginx.conf is not necessary, since it doesn't have the regex \abc part.
    I should change it to something like this?

    location = / {
      proxy_pass http://127.0.0.1:5601;
      proxy_read_timeout 90;
    }

I do have this need to access both http://xxx.xxx.com/ and http://xxx.xxx.com/abc where I would expect different kibana instances would be available for me.
Bottom line, what should I do to make http://xxx.xxx.com/ work?

  1. If my understanding is right, the server.defaultRoute : /app/kibna already redirected the request to http://xxx.xxx.com/abc/app/kibana. Should I still do rewrite like this rewrite ^/abc /abc/app/kibana? If not, what's the best way to rewrite the basePath? What about when I hit http://xxx.xxx.com, would this be redirected to http://xxx.xxx.com/app/kibana without any rewriting rules?

I know I have a lot of questions and you guys are not nginx experts, but this basePath is really confusing. I read all related discussion topics, I still couldn't figure out.
Really appreciate your help!

Thank you.

1 Like

Hey yeah sorry it is confusing - kibana will rewrite all browser side links, but the server routes will stay the same. In 6.3+ we've added another config to support server side rewriting too, which makes this all more straight foward

The shortest config that should help would be something like

    location /abc/ {
      proxy_pass http://127.0.0.1:5601/;
  1. the redirect will happen automatically
  2. yeah, it shouldn't be necessary
  3. /app/kibana is based on the browser side router, so after the root route is loaded some javascript is executed and will redirect you there. correct

Hey @meiyuan

Yeah, basePath can be really confusing, maybe if I explain the way it works in 5.2 it will help a little.

The basePath setting basically tells Kibana to rewrite all of it's internal routing to expect all requests to start with basePath. That means that when requests are proxied from nginx to Kibana they need to start with the basePath and Kibana will only consume the path bits after the basePath.

In regards to your desired setup of having two kibana's, one at / and one at /abc, I was able to get this working with the following config:

server {
  location /abc {
    rewrite ^/abc(.*)$ $1 break;
    proxy_pass http://127.0.0.1:5602;
  }

  location / {
    proxy_pass http://127.0.0.1:5601;
  }
}

One Kibana instance was started with the default flags and the second was started with: ./bin/kibana --server.port 5602 --server.basePath=/foo --verbose. The --verbose flag shows the requests that the Kibana server is receiving which might help debug invalid requests that are making it to the Kibana server and causing 404s.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.