# Kibana 7.2 behind nginx

**URL:** https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772
**Category:** Kibana
**Created:** [August 19, 2019, 3:58pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772 "2019-08-19T15:58:35Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![usfbh95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/usfbh95/32/45217_2.png) [@usfbh95](https://discuss.elastic.co/u/usfbh95)
#### Post date: [August 19, 2019, 3:58pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/1 "2019-08-19T15:58:35Z")

</div>

I'm trying to use nginx to authenticate users into kibana with a token that is passed as an query parameter (i.e. ?token=XXXXXX), I'm totally new to nginx and I'm facing several problem and would really appreciate some help.

when using a static authorization header it works just fine :

```
server{
        listen 8080;
        location / {
              proxy_pass http://localhost:5601;
              proxy_set_header Authorization "Basic ZWxhc3RpYzoxMjM0NTY=";
      }

```

but when I try something like :

```
server{
        listen 8080;
        #to open kibana
        location /kibana {
            proxy_pass http://localhost:5601/app/kibana;
            proxy_set_header Authorization "Basic $arg_token";
        }
        #for kibana to get it resources
        location / {
                 proxy_pass http://localhost:5601/;
        }
   }

```

and then I pass the token in the url, It works for a second but then I got redirected to [http://localhost:5601/logout?next=%2Fkibana%23%2Fhome%3F\_g%3D()&msg=SESSION\_EXPIRED](http://localhost:5601/logout?next=%2Fkibana%23%2Fhome%3F_g%3D()&msg=SESSION_EXPIRED) and then it prompt to login again...  
anyone can help please ?  
I'm using kibana 7.2  
Thank you !

---

<div class="post-metadata">

### Author: ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)
#### Post date: [August 19, 2019, 4:07pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/2 "2019-08-19T16:07:01Z")

</div>

Hey @usfbh95,

Do you need two `location` blocks defined? Can you try something like this:

```auto
server{
        listen 8080;
        location / {
                 proxy_pass http://localhost:5601/;
                 proxy_set_header Authorization "Basic $arg_token";
        }
   }

```

---

<div class="post-metadata">

### Author: ![usfbh95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/usfbh95/32/45217_2.png) [@usfbh95](https://discuss.elastic.co/u/usfbh95)
#### Post date: [August 19, 2019, 4:31pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/3 "2019-08-19T16:31:01Z")

</div>

Thank you for your quick answer, actually this the first thing I tried, something weird happens, if i enter a valid token there is some kind of redirection that causes the token to disappear and I get a security exception telling me that there is no token, otherwise (if the token is wrong) I get an error telling me that the token is wrong (so the token is still present)

---

<div class="post-metadata">

### Author: ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)
#### Post date: [August 19, 2019, 4:36pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/4 "2019-08-19T16:36:10Z")

</div>

> [@usfbh95](#):
>
> if i enter a valid token there is some kind of redirection that causes the token to disappear

Can you turn on verbose logging to get a better idea of what's causing this? In your `kibana.yml`, set:

```yml
logging.verbose: true
logging.quiet: false

```

---

<div class="post-metadata">

### Author: ![usfbh95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/usfbh95/32/45217_2.png) [@usfbh95](https://discuss.elastic.co/u/usfbh95)
#### Post date: [August 19, 2019, 4:48pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/5 "2019-08-19T16:48:30Z")

</div>

Here are the logs in case of correct token (the token is : ZWxhc3RpYzoxMjM0NTY= )  
[https://pastebin.com/z4AeTrUL](https://pastebin.com/z4AeTrUL)

Here are the logs when I pass wrong token : (the token is : WrongToken=)  
[https://pastebin.com/de21UunQ](https://pastebin.com/de21UunQ)

---

<div class="post-metadata">

### Author: ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)
#### Post date: [August 19, 2019, 4:59pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/6 "2019-08-19T16:59:58Z")

</div>

Thanks for the logs. I had a typo in my setup, can you try the following?

```auto
server{
        listen 8080;
        location / {
                 proxy_pass http://localhost:5601;
                 proxy_set_header Authorization "Basic $arg_token";
        }
   }

```

The difference here is that I removed the trailing slash in the `proxy_pass` command.

If you continue with the token-in-url route, you'll also need to strip off the `token` query parameter before sending the request to Kibana. Certain Kibana routes perform validation, and will reject requests that contain unexpected parameters. I'm not certain of the best way to do this with NGINX.

I'm also not sure what your entire system looks like, but this is likely not a secure setup. `$arg_token` is not an encrypted value, so anyone with access to the URLs will have access to the user credentials (username/password) since this is being pulled from a query string

---

<div class="post-metadata">

### Author: ![usfbh95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/usfbh95/32/45217_2.png) [@usfbh95](https://discuss.elastic.co/u/usfbh95)
#### Post date: [August 19, 2019, 5:04pm UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/7 "2019-08-19T17:04:29Z")

</div>

I did that but still have the same behavior 😕  
Can you explain to me how to do the stripp off the token as you said ?  
I know it's not so secured I'm just trying to get it to work

---

<div class="post-metadata">

### Author: ![usfbh95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/usfbh95/32/45217_2.png) [@usfbh95](https://discuss.elastic.co/u/usfbh95)
#### Post date: [August 24, 2019, 1:02am UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/8 "2019-08-24T01:02:06Z")

</div>

... any idea please ?

---

<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: [September 21, 2019, 1:02am UTC](https://discuss.elastic.co/t/kibana-7-2-behind-nginx/195772/9 "2019-09-21T01:02:06Z")

</div>

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