# Kibana and Nginx in subpath

**URL:** https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280
**Category:** Kibana
**Created:** [June 21, 2017, 12:07pm UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280 "2017-06-21T12:07:28Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rafaelangarita](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rafaelangarita](https://discuss.elastic.co/u/rafaelangarita)
#### Post date: [June 21, 2017, 12:07pm UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/1 "2017-06-21T12:07:28Z")

</div>

I've tried without success several configurations to get Kibana 4.5.4 to work in [https://myhost/kibana](https://myhost/kibana)

Nginx configuration 1:

```
server {

    listen 80;
    # SSL configuration

    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;

    auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/htpasswd.users;

     location ~ (/elasticsearch/|/app/|/bundles/|/kibana|/status|/plugins) {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;

            proxy_pass http://localhost:5601;
        }
}

```

with `server.basePath: "/kibana"`, I get `502 Bad Gateway`. Without setting the base path, I get:

`{"statusCode":404,"error":"Not Found"}`

Using [this approach](https://francispereira.com/reverse-proxying-kibana-with-nginx-sub-path.html,), I get

```
Courier Fetch Error: unhandled courier request error: Not Found
Version: 4.5.4
Build: 10000
Error: unhandled courier request error: Not Found
handleError@https://myhost/bundles/kibana.bundle.js?v=10000:80950:32
handleFailure@https://myhost/bundles/kibana.bundle.js?v=10000:80870:34
https://myhost/bundles/kibana.bundle.js?v=10000:80764:31
forEach@[native code]
https://myhost/bundles/kibana.bundle.js?v=10000:80762:26
processQueue@https://myhost/bundles/commons.bundle.js?v=10000:42404:31
https://myhost/bundles/commons.bundle.js?v=10000:42420:40
$digest@https://myhost/bundles/commons.bundle.js?v=10000:43459:37
$apply@https://myhost/bundles/commons.bundle.js?v=10000:43756:32
done@https://myhost/bundles/commons.bundle.js?v=10000:38205:54
completeRequest@https://myhost/bundles/commons.bundle.js?v=10000:38403:16
requestLoaded@https://myhost/bundles/commons.bundle.js?v=10000:38344:25
```

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [June 21, 2017, 10:33pm UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/2 "2017-06-21T22:33:46Z")

</div>

There is another topic with a similar problem here: [Reverse proxy Kibana](https://discuss.elastic.co/t/reverse-proxy-kibana/43647/14?u=tsullivan)

---

<div class="post-metadata">

### Author: ![rafaelangarita](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rafaelangarita](https://discuss.elastic.co/u/rafaelangarita)
#### Post date: [June 23, 2017, 6:42am UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/3 "2017-06-23T06:42:00Z")

</div>

I have already tried that. You can see it in the first Nginx configuration I posted here.

---

<div class="post-metadata">

### Author: ![waldo2188](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waldo2188/32/19463_2.png) [@waldo2188](https://discuss.elastic.co/u/waldo2188)
#### Post date: [June 23, 2017, 7:51am UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/4 "2017-06-23T07:51:34Z")

</div>

I have the same behavior with kibana 5.4.  
I can't figure out how to configure Nginx to work as reverse proxy.  
Is Kibana really ready to be used behind a reverse proxy who use subpath instead of domain name ?

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [June 23, 2017, 5:45pm UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/5 "2017-06-23T17:45:19Z")

</div>

> Is Kibana really ready to be used behind a reverse proxy who use subpath instead of domain name ?

Absolutely!

Here is a configuration that worked for me:

kibana.yml

```auto
server:
  basePath: "/awesome"
  host: "tim-virtual-machine.local"
  ssl:
    key: "/home/tim/server.key"
    cert: "/home/tim/server.crt"

```

nginx.conf

```auto
  # proxy kibana with a /awesome base path
  server {
    listen 5665;
    access_log logs/proxy.access-kbn.log main;
    server_name tim-virtual-machine.local;

    ssl_certificate /home/tim/server.crt;
    ssl_certificate_key /home/tim/server.key;

    ssl on;
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    location /awesome {
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;

      proxy_pass https://tim-virtual-machine.local:5601/;
      rewrite ^/awesome/(.*)$ /$1 break;
    }
  }

```

Now when I got to [https://tim-virtual-machine.local:5665/awesome](https://tim-virtual-machine.local:5665/awesome), I'm able to access Kibana.

I prefer adding the `rewrite` rule because it makes it explicit that the proxy needs to remove the base path from requests before they hit the Kibana server. There is a simpler, more implicit way to do this by adding slashes in the config appropriately. What I mean is, the following nginx config does the same thing, but the path removal is done automatically by nginx (note that the `location` line now has a slash at the end):

```auto
    location /awesome/ {
      proxy_pass https://tim-virtual-machine.local:5601/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }

```

---

<div class="post-metadata">

### Author: ![Yong\_Zhang](https://avatars.discourse-cdn.com/v4/letter/y/a183cd/32.png) [@Yong\_Zhang](https://discuss.elastic.co/u/Yong_Zhang)
#### Post date: [June 28, 2017, 4:50am UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/6 "2017-06-28T04:50:18Z")

</div>

I can't get it work with this config:

{"statusCode":404,"error":"Not Found"}

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [June 30, 2017, 8:59pm UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/7 "2017-06-30T20:59:39Z")

</div>

Yong\_Zhang, can you share the `server.basePath` setting that you have in your kibana.yml file, as well as your proxy configuration?

---

<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 29, 2017, 7:29am UTC](https://discuss.elastic.co/t/kibana-and-nginx-in-subpath/90280/9 "2017-07-29T07:29:09Z")

</div>

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