# server.basePath in version 5.2.2

**URL:** <https://discuss.elastic.co/t/server-basepath-in-version-5-2-2/185721>\
**Category:** Kibana\
**Created:** [June 13, 2019, 6:52pm UTC](https://discuss.elastic.co/t/server-basepath-in-version-5-2-2/185721 "2019-06-13T18:52:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![meiyuan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/meiyuan/32/44468_2.png) [@meiyuan](https://discuss.elastic.co/u/meiyuan)\
**Post date:** [June 13, 2019, 6:52pm UTC](https://discuss.elastic.co/t/server-basepath-in-version-5-2-2/185721/1 "2019-06-13T18:52:52Z")

</div>

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:

```auto
server.basePath: "/abc"

```

I know we have to rewrite the basePath in our proxy, [https://github.com/elastic/kibana/issues/6665](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](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](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](http://xxx.xxx.com/abc) ?

2. If `server.basePath` doesn't get appended to [http://xxx.xxx.com](http://xxx.xxx.com), then that means [http://xxx.xxx.com](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?

```auto
    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/](http://xxx.xxx.com/) and [http://xxx.xxx.com/abc](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/](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](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](http://xxx.xxx.com), would this be redirected to [http://xxx.xxx.com/app/kibana](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.

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [June 27, 2019, 2:30pm UTC](https://discuss.elastic.co/t/server-basepath-in-version-5-2-2/185721/2 "2019-06-27T14:30:42Z")

</div>

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

```auto
    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

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [June 27, 2019, 2:34pm UTC](https://discuss.elastic.co/t/server-basepath-in-version-5-2-2/185721/3 "2019-06-27T14:34:23Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 25, 2019, 2:39pm UTC](https://discuss.elastic.co/t/server-basepath-in-version-5-2-2/185721/4 "2019-07-25T14:39:23Z")

</div>

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