Running grafana behind ngnix causes bad request (invalid host)

I’m trying to run grafana behind a reverse proxy (ngnix), I’m following the guide and have the following:

	server {
		listen 443 ssl;
		server_name grafana.example.com;
		root /usr/share/nginx/html;
  		index index.html index.htm;

		# ! SSL config here

		# Your location blocks and proxy settings for Grafana go here
		location / {
			proxy_set_header Host grafana.example.com;
			proxy_pass http://grafana;
		}

		# Proxy Grafana Live WebSocket connections.
		location /api/live/ {
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection $connection_upgrade;
			proxy_set_header Host $http_host;
			proxy_pass http://grafana;
		}
	}

and the following in the grafana config:

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

# This is the minimum TLS version allowed. By default, this value is empty. Accepted values are: TLS1.2, TLS1.3. If nothing is set TLS1.2 would be taken
;min_tls_version = ""

# 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 = grafana.example.com

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

# 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 = http://grafana.example.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

When trying to access grafana.example.com, I get ‘Bad Request (Invalid Host)’.
Could anyone tell me what I’m doing wrong?

Like I said, I am following that guide.

I’m sorry, but I don’t see that in your initial post.
l see that you are not following doc precisely. Upstream block is missing in your nginx config for example (so you are forwarding to port 80, but Grafana is listening on default port 3000).

  1. I did mention this.

I’m following the guide

  1. The upstream block is ommitted here, but is present as follows:
	map $http_upgrade $connection_upgrade {
  	    default upgrade;
  	    '' close;
	}

	upstream grafana {
  	    server localhost:3000;
	}

I know it is a grafana issue, because the nginx logs do not report any errors.