# Grafana Nginx Auth Proxy

**URL:** <https://community.grafana.com/t/grafana-nginx-auth-proxy/215>\
**Category:** Configuration\
**Created:** [March 23, 2017, 5:06pm UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215 "2017-03-23T17:06:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmeterdude11](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@jmeterdude11](https://community.grafana.com/u/jmeterdude11)\
**Post date:** [March 23, 2017, 5:06pm UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/1 "2017-03-23T17:06:22Z")

</div>

I have been going round this for months and months as I am newbie to almost everything programming and environment.

I have my php application which has a MySQL backend. I have a Nginx webserver for the application.

I setup Grafana and am trying to use Nginx as auth proxy.

When I register/login into my app, user should be able to go directly into grafana without any credentials screen. In other words, Grafana should use my apps MySQL based authentication instead of its own authentication. I even have setup grafana to use MySQL instead of Sqllite.

But everytime I login or register, when I try to go Grafana, it goes to the grafana Login screen. What am I doing wrong.

My Nginx Conf is:

> location /grafana/  
> {  
> #proxy\_set\_header Host $host;  
> proxy\_pass [http://grafana.staged-by-discourse.com/](http://grafana.staged-by-discourse.com/);  
> #proxy\_set\_header X-WEBAUTH-USER $username;  
> #rewrite ^/grafana/(.\*) /$1 break;  
> }

My Grafana conf is:

> [auth.proxy]  
> enabled = true  
> header\_name = X-WEBAUTH-USER  
> header\_property = username  
> auto\_sign\_up = true

If I use the following option in nginx,

> proxy\_set\_header X-WEBAUTH-USER $username;

Then nginx fails with a message saying unknown variable username.

Please help.

---

<div class="post-metadata">

**Author:** ![torkel](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/torkel/32/20_2.png) [@torkel](https://community.grafana.com/u/torkel)\
**Post date:** [March 23, 2017, 6:58pm UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/2 "2017-03-23T18:58:44Z")

</div>

Yes, you need some auth setup in nginx in that case, like basic auth or some other nginx auth integration.

---

<div class="post-metadata">

**Author:** ![solugebefola](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/solugebefola/32/149_2.png) [@solugebefola](https://community.grafana.com/u/solugebefola)\
**Post date:** [March 24, 2017, 1:40pm UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/3 "2017-03-24T13:40:25Z")

</div>

In NGINX there is no preset variable called `username`. You need to set that variable to something, either culled from the request or set internally.

This is a list of nginx preset variables [http://nginx.org/en/docs/varindex.html](http://nginx.org/en/docs/varindex.html).

For anything else, you need to define it yourself, probably using lua, or passing the username to nginx in a query string (might be dangerous) or through some other means.

---

<div class="post-metadata">

**Author:** ![jmeterdude11](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@jmeterdude11](https://community.grafana.com/u/jmeterdude11)\
**Post date:** [March 24, 2017, 6:42pm UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/4 "2017-03-24T18:42:19Z")

</div>

Awesome. That gives me a sense of direction. Let me try something.

---

<div class="post-metadata">

**Author:** ![james222](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@james222](https://community.grafana.com/u/james222)\
**Post date:** [August 14, 2017, 11:47am UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/5 "2017-08-14T11:47:44Z")

</div>

> [@jmeterdude11](#):
>
> Awesome. That gives me a sense of direction. Let me try something.

hello, Were you completed this case? I also find the answer that use grafana auth proxy with nginx. I need your help. Can you help me?

---

<div class="post-metadata">

**Author:** ![roy651](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@roy651](https://community.grafana.com/u/roy651)\
**Post date:** [December 3, 2017, 4:31pm UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/6 "2017-12-03T16:31:28Z")

</div>

> [@How to use auth proxy with nginx?](https://community.grafana.com/t/how-to-use-auth-proxy-with-nginx/2257/3):
>
> For what it’s worth, thought I’d share here (and a couple of other places… cause it took me a while to crack…) how I linked my grafana to nginx authproxy using basic authentication: NGINX.CONF: (you have to create the password file beforehand) worker\_processes 1; daemon off; error\_log \<%= ENV["APP\_ROOT"] %\>/logs/error.log; events { worker\_connections 1024; } http { log\_format cloudfoundry '$http\_x\_forwarded\_for - $http\_referer - [$time\_local] "$request" $status $body\_bytes\_sent'; access\_l…

---

<div class="post-metadata">

**Author:** ![lemonieli](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@lemonieli](https://community.grafana.com/u/lemonieli)\
**Post date:** [September 19, 2018, 8:24am UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/7 "2018-09-19T08:24:40Z")

</div>

Hi. Is there any result of this integration?

---

<div class="post-metadata">

**Author:** ![darius121](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@darius121](https://community.grafana.com/u/darius121)\
**Post date:** [January 7, 2019, 5:11am UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/8 "2019-01-07T05:11:44Z")

</div>

FWIW I have this in my nginx config…  
server {  
listen [::]:443 ssl;  
listen 443 ssl;  
server\_name grafana.my.domain;

```
    auth_basic "Grafana";
    include /usr/local/etc/nginx/basic-auth.conf;
    proxy_set_header X-WEBAUTH-USER $remote_user;

    location / {
         proxy_pass http://grafana.staged-by-discourse.com/;
    }
}

```

And it works with the existing basic auth I use for other things.

The auth.proxy section of the grafana config looks like  
[auth.proxy]  
enabled = true  
header\_name = X-WEBAUTH-USER  
header\_property = username  
auto\_sign\_up = true

---

<div class="post-metadata">

**Author:** ![hemuangel17](https://avatars.discourse-cdn.com/v4/letter/h/9de0a6/32.png) [@hemuangel17](https://community.grafana.com/u/hemuangel17)\
**Post date:** [November 26, 2019, 6:27am UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/9 "2019-11-26T06:27:43Z")

</div>

Hi [darius121](https://community.grafana.com/u/darius121), [jmeterdude11](https://community.grafana.com/u/jmeterdude11)

Did this integration got completed sucessfully?

I have similar use case in Grafana. Your reply would help us in configuring SSO in Ngninx & Grafana.

Angel

---

<div class="post-metadata">

**Author:** ![gunasekaranpg](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@gunasekaranpg](https://community.grafana.com/u/gunasekaranpg)\
**Post date:** [July 13, 2020, 11:31am UTC](https://community.grafana.com/t/grafana-nginx-auth-proxy/215/10 "2020-07-13T11:31:33Z")

</div>

Hi,

Can i use Nginx Auth Prosy with Ifream and auto login to Grafana
