2

I would like to use dashboard as my nginx location for my grafana install.

The problems is grafana uses dashboard in some of it url's like https://example.com/grafana/dashboard/new?orgId=1, where I would like it to be https://example.com/dashboard/dashboard/new?orgId=1 and I think my nginx location is rewriting to https://example.com/dashboard/new?orgId=1.

When I have it setup to use grafana as the subpath it all work as expected;

grafana.ini:

[server]
http_addr = 127.0.0.1
domain = example.com
root_url = %(protocol)s://%(domain)s/grafana/

nginx config:

# Upstream Servers
upstream grafana_server {
    server localhost:3000;
}

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;

    root /var/www/example.com/html;

    index index.html index.htm;

    server_name example.com www.example.com;

    location /grafana/ {
        proxy_pass http://grafana_server/;
        proxy_set_header Host $host;
    }
}

But changing it to dashboard and navigating to https://example.com/dashboard/dashboard/new?orgId=1 results in the url been rewritten to https://example.com/dashboard/new?orgId=1

grafana.ini:

[server]
http_addr = 127.0.0.1
domain = example.com
root_url = %(protocol)s://%(domain)s/dashboard/

nginx config:

# Upstream Servers
upstream grafana_server {
    server localhost:3000;
}

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;

    root /var/www/example.com/html;

    index index.html index.htm;

    server_name example.com www.example.com;

    location /dashboard/ {
        proxy_pass http://grafana_server/;
        proxy_set_header Host $host;
    }
}

so I have tried a to do a rewrite in the nginx location but can't get it to work as required (really have no clue what to do here)

location ~ (\/dashboard\/) {
    proxy_pass http://grafana_server$1;
    proxy_set_header Host $host;
}

location ~ /dashboard/ {
    rewrite ^ /dashboard/$1;
    proxy_pass http://grafana_server;
    proxy_set_header Host $host;
}

Any help would be much appreciated.

Regards,

1 Answer 1

1

I know this is a bit late - but I stumbled upon the same issue and thought I'd going to share in case somebody else hits this thread:

This isn't an issue with nginx, but with grafana itself.

I could not solve it any other way but renaming the last part of the root_url in something different than /dashboard

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Phil, I found the same and ended up using /dashboards and all seems to be working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.