I'm trying to setup grafana as docker container behind Nginx using docker-compose. Any time I'm trying to reach the login page - I receive an error "Too many redirects".
Nginx config:
server {
listen 9999 ssl;
server_name S_NAME;
ssl_certificate ssl/S_NAME.crt;
ssl_certificate_key ssl/S_NAME.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 30m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
root /usr/share/nginx/www;
index index.html index.htm;
location /grafana/ {
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;
resolver 127.0.0.11 valid=30s;
set $grafana http://grafana:3000/;
proxy_pass $grafana;
rewrite ^/grafana/(.*) /$1 break;
proxy_connect_timeout 30m;
proxy_send_timeout 30m;
proxy_read_timeout 30m;
}
}
Docker-compose:
grafana:
image: grafana/grafana
ports:
- 3000:3000
environment:
GF_SECURITY_COOKIE_SECURE: "true"
GF_SERVER_ROOT_URL: "%(protocol)s://%(domain)s/grafana/"
GF_SERVER_DOMAIN: "test.com:9999"
restart: on-failure
Grafana spams these logs:
lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/ status=302
lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/ status=302
As for me, nginx is redirecting all requests to /grafana
, grafana redirects to /login
, but I may be wrong.
I already tried different variations of GF_SECURITY_COOKIE_SECURE
, GF_SERVER_ROOT_URL
and GF_SERVER_DOMAIN
, as well as removing sub-path /grafana
from nginx and without rewrite
property.
I'm using https
, so GF_SECURITY_COOKIE_SECURE
is needed to be set to true.
Do you have any ideas?
The error was in resolver
. I've added it to make nginx up even if there is no grafana, but for some reason, it didn't work.