Swag proxy-conf for Grafana

I have tried using the grafana proxy-conf which comes default in swag, however I get into a loop when access grafana via reverse proxy. Please could someone help

Here is my config

On Grafana, I’m using environment variable
GF_SERVER_DOMAIN = localhost
GF_SERVER_ROOT_URL = %(protocol)s://%(domain)s:%(http_port)s/grafana/
GF_SERVER_SERVE_FROM_SUB_PATH = true

and this is my proxy-conf for Grafana

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

server_name grafana.*;

include /config/nginx/ssl.conf;

client_max_body_size 0;

# enable for ldap auth, fill in ldap details in ldap.conf
#include /config/nginx/ldap.conf;

# enable for Authelia
#include /config/nginx/authelia-server.conf;

location / {
    # enable the next two lines for http auth
    #auth_basic "Restricted";
    #auth_basic_user_file /config/nginx/.htpasswd;

    # enable the next two lines for ldap auth
    #auth_request /auth;
    #error_page 401 =200 /ldaplogin;

    # enable for Authelia
    #include /config/nginx/authelia-location.conf;

    #include /config/nginx/proxy.conf;
    #include /config/nginx/resolver.conf;
    set $upstream_app 192.168.1.101;
    set $upstream_port 3000;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port/grafana;
    
    # Clear Authorization Header if you are using http auth and normal Grafana auth
    proxy_set_header    Authorization       "";        

}

}

When I try accessing grafana.xxxx.co.in it goes into a loop with this in the address bar https://grafana.xxxx.co.in/?chunkNotFound and a details error message

I tries replacing localhost in grafana domain variable and conf file but gives a 502 gateway error. Any help is really appreciated

welcome to the :grafana: forum, @vickybs

when you say SWAG I’m guessing you are referencing this?

I have it working with this grafana.subdomain.conf :

## Version 2021/05/18
# make sure that your dns has a cname set for grafana and that your grafana container is not using a base url

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

    server_name grafana.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    # enable for ldap auth, fill in ldap details in ldap.conf
    #include /config/nginx/ldap.conf;

    # enable for Authelia
    #include /config/nginx/authelia-server.conf;

    location / {
        # enable the next two lines for http auth
        #auth_basic "Restricted";
        #auth_basic_user_file /config/nginx/.htpasswd;

        # enable the next two lines for ldap auth
        #auth_request /auth;
        #error_page 401 =200 /ldaplogin;

        # enable for Authelia
        #include /config/nginx/authelia-location.conf;

        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        # use docker dns to resolve the ipaddress when the container name is used as address
        #resolver 127.0.0.11 valid=30s;
        #set  grafana;
        #set  3000;
        #set  http;
        #proxy_pass ://:;
        #set $upstream_app grafana;
        #set $upstream_port 3000;
        #set $upstream_proto http;
        #proxy_pass $upstream_proto://$upstream_app:$upstream_port;

        # Correctly configured proxy_pass
        proxy_pass http://grafana:3000;
    }
}

And also don’t forget to set the base_URL in grafana.ini in grafana docker container.
[server]
root_url = https://grafana.yourdomain.com
Grafana needs to be aware that it’s being accessed via a proxy, especially if you’re using a subdomain or subdirectory. You should set the root_url under the [server] section in Grafana’s configuration file (grafana.ini ) to match the external URL