Running Grafana under my SSL NGINX reverse proxy

Hello everyone,

I’ll admit right off the bat that I have 0 experience in NGINX because I started literally yesterday but I was able to learn about it a bit and set up everything I need.

The thing I always have issues on are the locations within my SSL server block, I was always able to fix stuff myself but it seems like I’m missing something with Grafana, so if any of you could help me figure out what that is I’ll gladly appreciate it.

My server is running on Ubuntu 18.04LTS.

I have a .conf configured for my server block which is this:

server {

    listen 80;
    return 301 https://$host$request_uri;

}

server {

    listen 443;
    server_name domain.cc www.domain.cc;
    ssl_certificate /path/to/ssl/certificate.crt;
    ssl_certificate_key /path/to/ssl/certificate.key;
    ssl on;
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log;

    if ($host != "domain.cc") {
            return 404;
            }

location / {

    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_pass http://localhost:8888;
    proxy_read_timeout 90;
    proxy_redirect http://localhost:8888 https://domain.cc;

    }

location /deluge {

    proxy_pass http://localhost:8112/;
    proxy_set_header X-Deluge-Base "/deluge/";
    include proxy-control.conf;
    add_header X-Frame-Options SAMEORIGIN;

    }

location /grafana {

    proxy_pass http://localhost:3000/;

    }

As you can see I have multiple locations and the first 2 run fine, under HTTPS and everything is correct.

Whenever I go to domain.cc/grafana tho, I get redirected to domain.cc/login which is a 404 obviously, but if I do “domain.cc/grafana/login” I get the warning about grafana not having loaded the applications correctly and check everything.

This is my Grafana.ini

[server]
;protocol = https

;http_addr =

;http_port = 3000

;domain = domain.cc

;enforce_domain = false

;root_url = https://domain.cc/grafana/

Now, I’m not sure what’s missing, I followed exactly what’s on this page https://grafana.com/docs/installation/behind_proxy/

Although I read on github that I could just put my full domain under the ;root_url= segment, but its still not working.

It seems like my proxy is redirecting me to /login/ when it should be /grafana/login…

what’s the issue here? Please someone enlighten me!

If anyone has the same issue:

The configuration inside NGINX is fine, the only problem is that the “Grafana.ini” mentioned here: https://grafana.com/docs/installation/behind_proxy/ isn’t the only one to modify, you’ll see there is one in /etc/grafana and one in /usr/share/grafana, for some reason when the server starts it loads both, once I changed it in both, it loaded up correctly