keycloak nginx doesn't work. infinity loading of AdminUI

64 views Asked by At

Could you help? I'm trying to config https keycloak and grafana through nginx. This is my nginx config file:

events {}

http {
    ssl_certificate /certs/my_crt.crt;
    ssl_certificate_key /certs/my_key.key;
    ssl_session_cache shared:SSL:5m;
    ssl_session_timeout 5m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    server 
    {
        listen 443 ssl;
        server_name grafana.my_domain.ru;
        location /
        {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_redirect off;
            proxy_pass http://grafana_app:3001;
        }
    }
    
    server 
    {
        listen 443 ssl;
        server_name keycloak.my_domain.ru;
        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-Host   $host;
            proxy_set_header    X-Forwarded-Server $host;
            proxy_set_header    X-Forwarded-Port   $server_port;
            proxy_set_header    X-Forwarded-Proto  $scheme;

            add_header Access-Control-Allow-Origin *;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_redirect off;
            proxy_pass http://keycloak:8080;
        }
    }
}

This is my docker-compose.yml file

docker-compose:
version: "3.7"

services:
  nginx:
    image: bitnami/nginx:1.25.3
    ports:
      - 443:443
    container_name: proxy_nginx
    volumes:
      - ./nginx/nginx.conf:/opt/bitnami/nginx/conf/nginx.conf:ro
      - ./nginx/certs:/certs
    depends_on:
      - gateway
      - react
    networks:
      - custom
  keycloak:
    container_name: keycloak
    image: docker.io/bitnami/keycloak:21.0.2
    ports:
      - "8080:8080"
    environment:
      - PROXY_ADDRESS_FORWARDING=true
      - KEYCLOAK_CREATE_ADMIN_USER=true
      - KEYCLOAK_DATABASE_HOST=db_kc
      - KEYCLOAK_DATABASE_PORT=5432
      - KEYCLOAK_DATABASE_NAME=kc_postgres
      - KEYCLOAK_DATABASE_USER=postgres
      - KEYCLOAK_DATABASE_PASSWORD=postgres
      - KEYCLOAK_PROXY_ADDRESS_FORWARDING=true
      - KEYCLOAK_FRONTEND_URL=https://keycloak.my_domain.ru
      - KEYCLOAK_ADMIN_USER=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
    depends_on:
      - db_kc
    networks:
      - custom
  grafana:
    image: bitnami/grafana:9.4.7
    container_name: grafana_app
    restart: always
    ports:
      - "3001:3001"
    environment:
      - GF_DATABASE_TYPE=postgres
      - GF_DATABASE_HOST=db_kc
      - GF_DATABASE_NAME=kc_postgres
      - GF_DATABASE_USER=postgres
      - GF_DATABASE_PASSWORD=postgres
      - KEYCLOAK_REALM=************
      - KEYCLOAK_CLIENT_ID=grafana
      - KEYCLOAK_SECRET=************
      - KEYCLOAK_DOMEN=keycloak.my_domain.ru
    depends_on:
      - db_kc
      - keycloak
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./custom.ini:/etc/grafana/grafana.ini
      - grafana_data:/opt/bitnami/grafana/data
      - ./provisioning:/etc/grafana/provisioning
    networks:
      - custom

The error is infinity loading of Admin UI on https. If i use http with ip address and port so will be all ok. Dev console in the browser shows me the error:

Refused to frame 'http://keycloak.my_domain.ru/' because it violates the following Content Security Policy directive: "frame-src 'self'".

How to fix it? I was trying to search this problem in the internet (rewrite nginx config or docker-compose file) but it didn't help me yet.

I was trying this tutorial: https://keycloak.discourse.group/t/keycloak-docker-deployment-no-login-possible/7275

0

There are 0 answers