Grafana using sub path

Hey guys,

Someone is using grafana with subpath?

I’ve made this following changes:

domain = mydomain.com
root_url = http://mydomain.com/grafana/
serve_from_sub_path = true

But it is not working… I’m using Ubuntu 20.04 with Grafana 8.4.4.

Hi,
I have used subpath and it is working fine for me.
in my config this is what i have set
domain = localhost
enforce_domain = false
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true

what is the error you are getting ?

Hi,

Thanks for your answer.

My goal is access my url like:

mydomain.com/grafana
Without the 3000 port

Once I tried it I got the error:

Not Found

The requested URL was not found on this server.

My config:

domain = mydomain.com
enforce_domain = false
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true

For anyone out there struggling with this.

Nginx config

server { etc... etc..

    set $grafana_upstream "grafana";

    location = /grafana {
      return 301 /grafana/;
    }

    location /grafana/ {
      limit_req zone=ui_rate burst=10 nodelay;
      proxy_set_header Host $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 $scheme;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-Port 443;
      proxy_read_timeout 90s;
      proxy_redirect off;
      proxy_pass http://$grafana_upstream:3000;
    }
}

grafana.ini config

[server]
protocol = http
http_addr = 0.0.0.0
http_port = 3000
domain = <your_domain>
enforce_domain = true
root_url = %(protocol)s://%(domain)s/grafana/
serve_from_sub_path = true
router_logging = true
static_root_path = public
enable_gzip = false
read_timeout = 0

Grafana Documentation states it like this:

Alternative for serving Grafana under a sub path

Note

You only need this if you don’t handle the sub path serving via your reverse proxy configuration.

If you don’t want or can’t use the reverse proxy to handle serving Grafana from a sub path, you can set the configuration variable server_from_sub_path to true.

  1. Include the sub path at the end of the root_url.
  2. Set serve_from_sub_path to true:

Source: [Grafana Configure-nginx](https://grafana.com/tutorials/run-grafana-behind-a-proxy/#configure-nginx)

Some URI’s need connection upgrade: /grafana/api/live/

proxy_set_header Upgrade              $http_upgrade;
proxy_set_header Connection           $http_connection;