# Grafana / HTTPS / Nginx Proxy

**URL:** <https://community.grafana.com/t/grafana-https-nginx-proxy/17016>\
**Category:** Configuration\
**Created:** [May 7, 2019, 5:47am UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016 "2019-05-07T05:47:11Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![zuntaruk](https://avatars.discourse-cdn.com/v4/letter/z/49beb7/32.png) [@zuntaruk](https://community.grafana.com/u/zuntaruk)\
**Post date:** [May 7, 2019, 5:47am UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/1 "2019-05-07T05:47:11Z")

</div>

So, I’m starting to feel pretty crazy. I’m unable to access grafana through the https proxy. I’ve looked at the documentation for this a multitude of times. Here is my nginx config:

```
server {
  server_name my.domain.name;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  ssl on;
  ssl_certificate /etc/ssl/certs/cloud_flare_cert.pem;
  ssl_certificate_key /etc/ssl/private/cloud_flare_key.pem;
  index index.html index.htm;

location / {
  proxy_pass http://grafana.staged-by-discourse.com/;
  proxy_set_header Host $http_host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto "https";
  }
}

```

With that setup, I have the following in my grafana.ini file.

```
instance_name = my.domain.name
[server]
protocol = https

# The http port to use
http_port = 3000

# The public facing domain name used to access grafana from a browser
domain = my.domain.name

# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
enforce_domain = true

# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = https://my.domain.name/

# https certs & key file
cert_file = /etc/grafana/cloud_flare_cert.pem
cert_key = /etc/grafana/cloud_flare_key.pem

```

For the life of me, I cannot figure out what I can’t access grafana by heading to [https://my.domain.name](https://my.domain.name).

I do see the following text in my nginx error.log file when I attempt to load the URL:

```
2019/05/07 05:28:32 [error] 6443#6443: *1 upstream sent no valid HTTP/1.0 header while reading response header from upstream

```

I’m hoping I’m just tired and missed something silly somewhere. As the cert file names show, I am behind Cloudflare, but I’m not sure what that does in terms of accessibility.

Any assistance here would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![danielgonzalez](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/danielgonzalez/32/7125_2.png) [@danielgonzalez](https://community.grafana.com/u/danielgonzalez)\
**Post date:** [May 7, 2019, 1:11pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/2 "2019-05-07T13:11:02Z")

</div>

You can solve it like this, edit grafana config:

```
instance_name = my.domain.name
[server]
#here
protocol = http

# The http port to use
http_port = 3000

# The public facing domain name used to access grafana from a browser
domain = my.domain.name

# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
enforce_domain = true

# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = https://my.domain.name/

# https certs & key file
#Here
#cert_file = /etc/grafana/cloud_flare_cert.pem
#cert_key = /etc/grafana/cloud_flare_key.pem

```

you do not need (I do not believe) https between grafana and the Nginx.  
Or maybe you can edit Nginx.conf, But I’m not sure.

```
location / {
  #here
  proxy_pass https://community.grafana.com/;
  proxy_set_header Host $http_host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto "https";
  }
```

---

<div class="post-metadata">

**Author:** ![zuntaruk](https://avatars.discourse-cdn.com/v4/letter/z/49beb7/32.png) [@zuntaruk](https://community.grafana.com/u/zuntaruk)\
**Post date:** [May 7, 2019, 5:21pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/3 "2019-05-07T17:21:03Z")

</div>

I’ll give that a go and let you know what happens. Thanks!

---

<div class="post-metadata">

**Author:** ![zuntaruk](https://avatars.discourse-cdn.com/v4/letter/z/49beb7/32.png) [@zuntaruk](https://community.grafana.com/u/zuntaruk)\
**Post date:** [May 7, 2019, 6:54pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/4 "2019-05-07T18:54:18Z")

</div>

Oh my word. That got me in. Thank you! So, because I’m handling the HTTPS stuff with Nginx, I need not worry about it with grafana? Good to know!

---

<div class="post-metadata">

**Author:** ![mbonne1](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mbonne1](https://community.grafana.com/u/mbonne1)\
**Post date:** [May 25, 2020, 1:22am UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/5 "2020-05-25T01:22:35Z")

</div>

Thanks for the tip. This worked  
Grafana, nginx, and letsencrypt - installed on macOS with homebrew.

---

<div class="post-metadata">

**Author:** ![techies](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@techies](https://community.grafana.com/u/techies)\
**Post date:** [April 16, 2021, 12:04pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/6 "2021-04-16T12:04:22Z")

</div>

Hi @danielgonzalez,

I have tried exactly the same but for am still getting the below error.

```
2021/04/16 11:55:28 [error] 12842#12842: *1 SSL_do_handshake() failed (SSL: error:1408F10B:SSL routines:ssl3_get_record:wrong version number) while SSL handshaking to upstream, client: 80. **.**.**, server: my.proxy.com, request: "GET / HTTP/2.0", upstream: "https://127.0.0.1:3000/", host: "my.proxy.com"

```

Pasting my config file details below.

/etc/nginx/sites-available/default

> server {  
> server\_name [my.proxy.com](http://my.proxy.com);  
> listen 443 ssl http2;  
> listen [::]:443 ssl http2;  
> ssl on;  
> ssl\_certificate /etc/nginx/ssl-certs/godaddy\_cert.crt;  
> ssl\_certificate\_key /etc/nginx/ssl-certs/godaddy\_key.key;  
> root /var/www/example.com;  
> index index.html;  
> location / {  
> proxy\_pass [https://community.grafana.com/](https://community.grafana.com/);  
> proxy\_set\_header Host $http\_host;  
> proxy\_set\_header X-Real-IP $remote\_addr;  
> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
> proxy\_set\_header X-Forwarded-Proto “https”;  
> }  
> }

#/etc/grafana/grafana.ini

> ```
> > instance_name = my.proxy.com
> > [server]
> > 
> > # Protocol (http, https, h2, socket)
> > 
> > protocol = http
> > 
> > # The ip address to bind to, empty will bind to all interfaces
> > 
> > ;http_addr =
> > 
> > # The http port to use
> > 
> > http_port = 3000
> > 
> > # The public facing domain name used to access grafana from a browser
> > 
> > domain = my.proxy.com
> > 
> > # Redirect to correct domain if host header does not match domain
> > 
> > # Prevents DNS rebinding attacks
> > 
> > enforce_domain = true
> > 
> > # The full public facing url you use in browser, used for redirects and emails
> > 
> > # If you use reverse proxy and sub path specify full url (with sub path)
> > 
> > #root_url = %(protocol)s://%(domain)s:%(http_port)s/
> > 
> > root_url = https://my.proxy.com/
> > 
> > # Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
> > 
> > ;serve_from_sub_path = false
> > 
> > # Log web requests
> > 
> > ;router_logging = false
> > 
> > # the path relative working path
> > 
> > #static_root_path = public
> > 
> > # enable gzip
> > 
> > enable_gzip = false
> > 
> > # https certs & key file
> > 
> > #cert_file = /etc/nginx/ssl-certs/godaddy_cert.crt
> > 
> > #cert_key = /etc/nginx/ssl-certs/godaddy_key.key
> 
> ```

---

<div class="post-metadata">

**Author:** ![danielgonzalez](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/danielgonzalez/32/7125_2.png) [@danielgonzalez](https://community.grafana.com/u/danielgonzalez)\
**Post date:** [April 16, 2021, 12:21pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/7 "2021-04-16T12:21:19Z")

</div>

Could you try this config file?

> [@techies](#):
>
> server {  
> listen 80;  
> server\_name [my.proxy.com](http://my.proxy.com);  
> return 301 https://my.proxy.com$request\_uri;  
> }
> 
> server {  
> server\_name [my.proxy.com](http://my.proxy.com);  
> listen 443 ssl http2;  
> listen [::]:443 ssl http2;  
> ssl on;  
> ssl\_certificate /etc/nginx/ssl-certs/godaddy\_cert.crt;  
> ssl\_certificate\_key /etc/nginx/ssl-certs/godaddy\_key.key;  
> root /var/www/example.com;  
> index index.html;  
> location / {  
> proxy\_pass [http://grafana.staged-by-discourse.com/](http://grafana.staged-by-discourse.com/);  
> proxy\_set\_header Host $http\_host;  
> proxy\_set\_header X-Real-IP $remote\_addr;  
> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
> proxy\_set\_header X-Forwarded-Proto “https”;  
> }  
> }

---

<div class="post-metadata">

**Author:** ![techies](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@techies](https://community.grafana.com/u/techies)\
**Post date:** [April 16, 2021, 2:02pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/8 "2021-04-16T14:02:28Z")

</div>

Thanks, @danielgonzalez for the quick update, but still am getting the same error.

---

<div class="post-metadata">

**Author:** ![danielgonzalez](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/danielgonzalez/32/7125_2.png) [@danielgonzalez](https://community.grafana.com/u/danielgonzalez)\
**Post date:** [April 16, 2021, 2:32pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/9 "2021-04-16T14:32:22Z")

</div>

Did you restart the nginx server?

---

<div class="post-metadata">

**Author:** ![techies](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@techies](https://community.grafana.com/u/techies)\
**Post date:** [April 17, 2021, 5:58am UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/10 "2021-04-17T05:58:23Z")

</div>

Thanks @danielgonzalez, it is working. I missed to remove s from the proxy\_pass [http://grafana.staged-by-discourse.com/;](http://grafana.staged-by-discourse.com/;)

---

<div class="post-metadata">

**Author:** ![sanmh94](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@sanmh94](https://community.grafana.com/u/sanmh94)\
**Post date:** [September 7, 2023, 1:00pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/11 "2023-09-07T13:00:09Z")

</div>

> [@techies](#):
>
> [http://grafana.staged-by-discourse.com/](http://grafana.staged-by-discourse.com/;)

hi, we are trying with this configuration in nginx.conf

```auto
  server {
        listen 443 ssl http2 default_server;
        ssl_certificate "/etc/nginx/cert/cert.pem";
        ssl_certificate_key "/etc/nginx/cert/certkey.pem";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
        root /usr/share/nginx/html;
		
		location / {
        }

		location /grafana/
		{
		    proxy_pass https://localhost:3000/;
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto "https";
			#add_header Access-Control-Allow-Origin $http_origin; #this mirrors back whatever domain the request came from as authorized, as
			#add_header "Access-Control-Allow-Credentials" "true"; #as long as it matches one of your if statements
			#add_header "Access-Control-Allow-Methods" "GET, OPTIONS";
			#add_header "Access-Control-Allow-Headers" "Authorization, origin, accept";
			#rewrite ^/grafana/(.*) /$1 break;
		}
   }

```

and this in grafana.ini, but it does not work

```auto
[server]
# Protocol (http, https, h2, socket)
protocol = http

# The ip address to bind to, empty will bind to all interfaces
;http_addr =

# The http port to use
http_port = 3000

# The public facing domain name used to access grafana from a browser
;domain = localhost

# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
enforce_domain = true

# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = https://10.138.1.117:3000/grafana/

# Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
serve_from_sub_path = true

# Log web requests
;router_logging = false

# the path relative working path
;static_root_path = public

# enable gzip
;enable_gzip = false

# https certs & key file
cert_file = /etc/ssl/certs/cert.pem
cert_key = /etc/ssl/certs/certkey.pem

```

but the proxy does not work, can you see anything?

---

<div class="post-metadata">

**Author:** ![fadjar340](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/fadjar340/32/10236_2.png) [@fadjar340](https://community.grafana.com/u/fadjar340)\
**Post date:** [September 7, 2023, 1:07pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/12 "2023-09-07T13:07:24Z")

</div>

Hi,

if the proxy already ssl terminate, I think you don’t need run grafana in https mode.  
So, you can comment the cert in grafana.ini and root\_url just the domain of the vhost in the nginx.conf.  
Also, the nginx.conf since using https, you need to put server\_name according to your ssl certificare name.

First of all, make sure the grafana starting at port 3000 using curl [http://localhost:3000](http://localhost:3000),  
then you can check the nginx using nginx -t to make sure all the configuration is good.\

After all test woked fine, just restart the nginx,  
To make sure all the setup working, you can use curl https://\<your\_server\_name\>/grafana

Regards,  
Fadjar

---

<div class="post-metadata">

**Author:** ![sanmh94](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@sanmh94](https://community.grafana.com/u/sanmh94)\
**Post date:** [September 8, 2023, 7:02am UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/13 "2023-09-08T07:02:09Z")

</div>

@fadjar340 i see this on docker logs

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/5/6/568557f8595381adf659008a46d606adc1f3e2e6.png)

do you know how can i solve?

---

<div class="post-metadata">

**Author:** ![fadjar340](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/fadjar340/32/10236_2.png) [@fadjar340](https://community.grafana.com/u/fadjar340)\
**Post date:** [September 8, 2023, 2:47pm UTC](https://community.grafana.com/t/grafana-https-nginx-proxy/17016/14 "2023-09-08T14:47:23Z")

</div>

Hi, you can comment like below:  
`# root /usr/share/nginx/html;`

Regards,  
Fadjar
