Score:0

Conteinerized Keycloak behind Nginx reverse proxy requests localhost

us flag

Working setup

I have a configuration of

  • external VPS with public IP that has Nginx reverse proxy (A)
  • internal server with Nginx (B)
  • standalone application (not containerized) Keycloak 17.0.1

Which looks like this. I had a domain registrered for that server which is (let's say) auth.example.com

When I go to https://auth.example.com I can see regular keycloak page with link to admin console.

enter image description here

By clicking on the administration console I can properly login to manage master realm.

enter image description here

The problem

As soon as I containerize keycloak all links for administration console and some scripts are no longer working as they are changed from https://auth.example.com to https://localhost

enter image description here

Configs

By containerizing keycloak I did not modify any of the nginx configs.

Nginx A

        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;
                proxy_pass http://[nginx b ip];
        }

Nginx B

server
{
        server_name auth.example.com;
        location /
        {
            proxy_pass http://localhost:[exposed docker port];
        }
        listen 80;
}

Standalone keycloak (working command)

/usr/bin/bash bin/kc.sh start --proxy edge --hostname=auth.example.com --db-url-host localhost --db-username keycloak --db-password password

Dockerized keycloak (docker-compose)

  keycloak:
    image: quay.io/keycloak/keycloak:latest
    command: start --auto-build --features=token-exchange --hostname-strict-backchannel=true --hostname=auth.example.com
    depends_on:
      - db
    environment:
      KC_METRICS_ENABLED: "true"
      DB_VENDOR: [somedbvendor]
      DB_ADDR: db
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_PASSWORD: password
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
      KC_PROXY: edge
      PROXY_ADDRESS_FORWARDING: "true"
    ports:
      - "8081:8080"
    networks:
      - net

I would like to containerize whole application I have and their dependencies and keycloak is a first step that I cannot complete.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.