Skip to content

Commit f1c0543

Browse files
committed
set keycloak behind reverse-proxy
1 parent 9ab1e66 commit f1c0543

4 files changed

Lines changed: 31 additions & 8 deletions

File tree

docker-compose.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ services:
1717
KC_DB_PASSWORD: "password"
1818

1919
KC_HOSTNAME: "localhost"
20-
KC_HOSTNAME_PORT: 8080
2120
KC_HOSTNAME_STRICT: false
21+
KC_PROXY: edge
22+
KC_HTTP_RELATIVE_PATH: /keycloak
23+
KC_HTTP_ENABLED: true
2224

2325
KEYCLOAK_ADMIN: "admin"
2426
KEYCLOAK_ADMIN_PASSWORD: "admin"
25-
command: start-dev --import-realm
27+
command: start --import-realm
2628
depends_on:
2729
- keycloak-postgres
2830
volumes:
2931
- "./keycloak:/opt/keycloak/data/import:ro"
30-
ports:
31-
- "8080:8080"
3232

3333
postgres:
3434
image: postgres:15.15
@@ -45,6 +45,7 @@ services:
4545

4646
backend:
4747
image: ghcr.io/helpwave/tasks-backend:latest
48+
build: backend
4849
environment:
4950
DATABASE_HOSTNAME: "postgres"
5051
DATABASE_NAME: "postgres"
@@ -67,19 +68,24 @@ services:
6768
web:
6869
image: ghcr.io/helpwave/tasks-web:latest
6970
environment:
70-
ISSUER_URI: "http://localhost:8080/realms/tasks"
71-
CLIENT_ID: "tasks-web"
71+
RUNTIME_ISSUER_URI: "http://localhost/keycloak/realms/tasks"
72+
RUNTIME_REDIRECT_URI: "http://localhost/auth/callback"
73+
RUNTIME_POST_LOGOUT_REDIRECT_URI: "http://localhost/"
74+
RUNTIME_CLIENT_ID: "tasks-web"
7275
depends_on:
7376
- backend
7477

7578
proxy:
7679
image: ghcr.io/helpwave/tasks-proxy:latest
80+
build: proxy
7781
environment:
82+
KEYCLOAK_HOST: keycloak:8080
7883
BACKEND_HOST: backend:80
7984
FRONTEND_HOST: web:80
8085
ports:
8186
- "80:80"
8287
depends_on:
88+
- keycloak
8389
- backend
8490
- web
8591

proxy/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ COPY nginx.conf /etc/nginx/nginx.conf.template
44

55
EXPOSE 80
66

7-
CMD ["/bin/sh", "-c", "envsubst '${FRONTEND_HOST} ${BACKEND_HOST}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && exec nginx -g 'daemon off;'"]
7+
CMD ["/bin/sh", "-c", "envsubst '${FRONTEND_HOST} ${BACKEND_HOST} ${KEYCLOAK_HOST}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && exec nginx -g 'daemon off;'"]

proxy/nginx.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ http {
1414
server ${BACKEND_HOST};
1515
}
1616

17+
upstream keycloak_upstream {
18+
server ${KEYCLOAK_HOST};
19+
}
20+
21+
1722
server {
1823
listen 80;
1924
server_name localhost;
@@ -31,6 +36,17 @@ http {
3136
proxy_set_header Connection "upgrade";
3237
}
3338

39+
location /keycloak/ {
40+
proxy_pass http://keycloak_upstream/keycloak/;
41+
42+
proxy_set_header Host $host;
43+
proxy_set_header X-Real-IP $remote_addr;
44+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
45+
proxy_set_header X-Forwarded-Proto $scheme;
46+
47+
proxy_http_version 1.1;
48+
}
49+
3450
location / {
3551
proxy_pass http://frontend_upstream;
3652

simulator/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.env
2-
2+
.env*
3+
!.env.example

0 commit comments

Comments
 (0)