Grafana Ngin Reverse Proxy ERR_TOO_MANY_REDIRECT to login

I tried to setup grafana over nginx reverse proxy but I’m getting following error:
If you’re seeing this Grafana has failed to load its application files

  1. This could be caused by your reverse proxy settings.
  2. If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath
  3. If you have a local dev build make sure you build frontend using: yarn start, yarn start:hot, or yarn build
  4. Sometimes restarting grafana-server can help

also too many redirects in the network tab to login page.

I’ve followed the auth proxy setup doc but still I haven’t got it working.

What you expected to happen :
Grafana UI should work normally without any redirection issue.

How to reproduce it (as minimally and precisely as possible) :
here is my nginx.conf
`worker_processes 1;

events { worker_connections 1024; }

http {

log_format compression '$remote_addr - $remote_user [$time_local] ’
'"$request" $status $upstream_addr ’
‘"$http_referer" “$http_user_agent” “$gzip_ratio”’;

upstream docker-grafana {
server grafana:3000;
}

server {
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
listen 8081;

    location / {
            root /usr/share/nginx/html;
            index index.html index.htm;
            try_files $uri $uri/ /index.html =404;
    }

    location /grafana {
        set $user "";
        if ($args ~ "^user=(.+)") {
           set $user $1;
        }
        add_header X-USER "$user";
        add_header X-Forwarded-Host "$server_name";
        add_header X-Forwarded-For "$proxy_add_x_forwarded_for";
        add_header X-HOST "$host";
        add_header X-REMOTE-ADDR "$remote_addr";

        proxy_pass         http://docker-grafana;
        proxy_redirect     off;
        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-Host $server_name;
        proxy_set_header   X-Forwarded-Proto http;
        proxy_set_header   X-WEBAUTH-USER $user;
        proxy_set_header   Authorization "";
    }
 }

}`

Here is my grafana.ini file:
`[server]
domain = 130.147.136.40:3000
root_url = http://130.147.136.40:3000/grafana/

[users]
allow_sign_up = false
auto_assign_org = true
auto_assign_org_role = Editor

[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = false`

Here is my docker-compose file:
version: '2' services: reverseproxy: image: reverseproxy container_name: reverseproxy ports: - 8081:8081 restart: always prometheus: image: prom/prometheus container_name: prometheus volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml command: - '--config.file=/etc/prometheus/prometheus.yml' depends_on: - reverseproxy ports: - '9090:9090' restart: always pushgateway: image: prom/pushgateway container_name: pushgateway command: - '--persistence.file=pushgateway-metrics' - '--persistence.interval=10s' depends_on: - reverseproxy ports: - '9091:9091' restart: always grafana: image: grafana/grafana container_name: grafana volumes: - ./grafana.ini:/etc/grafana/grafana.ini environment: - GF_SECURITY_ADMIN_PASSWORD=admin - GF_AUTH_OAUTH_AUTO_LOGIN=true depends_on: - reverseproxy - prometheus ports: - "3000:3000" restart: always

whereas reverse-proxy is the container of Nginx.

Please, someone, help me fix this issue.

I just tried an nginx reverse proxy for authentication with the latest master revision of Grafana, and it works well. I did the following inside the Grafana repo:

  1. Edit devenv/docker/blocks/nginx_proxy/nginx.conf, uncommenting the auth_basic* settings.
  2. make devenv sources=nginx_proxy
  3. cp conf/sample.ini conf/custom.ini
  4. Change root_url in conf/custom.ini: root_url = %(protocol)s://%(domain)s:10080/grafana/
  5. In one terminal, start the webpack server: make deps && yarn start
  6. In another terminal, start the Grafana server: make run
  7. Once both the webpack and Grafana servers are running, visit http://localhost:10080/grafana

After point 7, you should be able to log into Grafana via nginx, that worked for me at least. Once you’ve got this basic setup working, you should try to figure out why your setup doesn’t work.

Hi,

i also got the same erroe " localhost redirected you too many times." i am using the default NGINX as grafana given

Hi,
Can you share me the ifream src value and Nginx, ini value to modified

I think it is fixed with the serve_from_subpath option in grafana.ini. Please check the exact option format in the Grafana docs - I don’t have it in front of me right now