Repository navigation
Keycloak behind a Nginx Proxy Manager (NPM) #37021
Replies: 2 comments
|
This is apparently impossible. |
|
@PelleHanses @vmsman After suffering for 16+ hours, I have been able to put something together. I use NPM Plus, so it might be slightly different in the nginx section for you .env:Genuinely incredibly angry at that hostname admin env. I spent way too long trying to get that to work and testing different setups before I gave up. Every issue with this basically says "wontfix, you just don't understand how it works" and provide no examples so we can understand how it works. Maybe being so hard to use, explain, or even give a working example of is evidence to the fact that it is broken? But I digress. docker-compose.ymlservices:
keycloak:
container_name: keycloak
image: quay.io/keycloak/keycloak:26.6.3
command: start
environment:
- "TZ=${TIMEZONE}"
- "KC_DB=postgres"
- "KC_DB_URL=jdbc:postgresql://kcpostgres/${POSTGRES_DB}"
- "KC_DB_USERNAME=${POSTGRES_USER}"
- "KC_DB_PASSWORD=${POSTGRES_PASSWORD}"
# - "KC_HOSTNAME_DEBUG=true" # Only enable when needed
- "KC_HOSTNAME=${KC_HOSTNAME}"
# - "KC_HOSTNAME_ADMIN=${KC_HOSTNAME_ADMIN}" # Cannot, for the life of me, get this shit to work properly. Avoid at all costs.
- "KC_HOSTNAME_BACKCHANNEL_DYNAMIC=true" # Set to false to allow client-server communication through a private network. See https://docs.redhat.com/en/documentation/red_hat_build_of_keycloak/22.0/html/server_guide/hostname-#hostname-backend
# - "KC_HOSTNAME_STRICT=false" # "If KC_HOSTNAME is specified, KC_HOSTNAME_STRICT is effectively ignored" - Per KC logs at startup
- "KC_HTTP_ENABLED=true"
- "KC_PROXY_HEADERS=xforwarded"
- "KC_HEALTH_ENABLED=true"
- "KC_METRICS_ENABLED=true"
- "KC_LOG_LEVEL=info"
# - "KC_BOOTSTRAP_ADMIN_USERNAME=${KC_BOOTSTRAP_ADMIN_USERNAME}" # Only enable when needed
# - "KC_BOOTSTRAP_ADMIN_PASSWORD=${KC_BOOTSTRAP_ADMIN_PASSWORD}" # Only enable when needed
ports:
- "${KC_PORTNUMBER}:8080"
- "9000:9000"
# - "57801:8443" # admin interface avaiable on local network
volumes:
- ./keycloak/keycloak.conf:/opt/keycloak/configuration/keycloak.conf
- ./keycloak/providers:/opt/keycloak/providers
- ./keycloak/data:/opt/keycloak/data
- ./keycloak/themes:/opt/keycloak/themes
- "${PRIVKEY_PEM_PATH}:/opt/keycloak/conf/server.key.pem"
- "${FULLCHAIN_PEM_PATH}:/opt/keycloak/conf/server.crt.pem"
depends_on:
kcpostgres:
condition: service_healthy
networks:
- keycloak_network
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/health/live"]
interval: 10s
timeout: 10s
retries: 20
kcpostgres:
container_name: kcpostgres
image: postgres:18-alpine
environment:
TZ: ${TIMEZONE}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- ./keycloak/postgresql:/var/lib/postgresql
networks:
- keycloak_network
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U keycloak"]
interval: 10s
timeout: 5s
retries: 5
networks:
keycloak_network:
driver: bridgenpm settingsDomain Names: KC_HOSTNAME in your .env In custom locations, set: In TLS settings, force HTTPS. May need to enable websockets but I don't have that setting anymore in npm plus. For the overall custom nginx configuration, you should only need this And that was all! Let me know if it worked for ya. |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
is someone running Keycloak in docker and have a Nginx proxy manager as docker as reverse proxy in fron of Keycloak?
Can you please give me some hints on how to setup both Keycloak and Nginx proxy manager to get it to work?
In this first setup we have both Keycloak and Nginx proxy manager on the same host.
Thanks
PelleH
All reactions