4
votes

I would like to access a Keycloak server that is on the internet and not on my docker network. I want to hide the domain of the Keycloak server behind my own domain. So if I go to http://localhost/auth/ then the page from the Keycloak server should be displayed. I don't want to have a redirect to the actual Keycloak server.

Drawing

I have tried the following configuration but it does not work. When I go to http://localhost/auth I get a "404 page not found". I hope you can help me. Thank you very much for your help :)

docker-compose.yml

version: "3.7"

services:

  proxy:
    image: traefik:v2.2
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.file=true"
      - "--providers.file.filename=/etc/traefik/rules.yml"
      - "--entrypoints.web.address=:80"
    ports:
      - 80:80
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./rules.yml:/etc/traefik/rules.yml

  website:
    image: containous/whoami
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.website.rule=Host(`localhost`)"
      - "traefik.http.routers.website.entrypoints=web"

rules.yml

http:
  routers:
    my-route:
      rule: "Host(`localhost`) && PathPrefix(`/auth`)"
      service: my-keycloak-server
  services:
    my-keycloak-server:
      loadBalancer:
        servers:
          - url: "https://keycloak.domain.com/auth"
1
Why traefik? The same solution is also possible with nginx. Maybe it is easier than traefik.akop
@akop generally several reasons: 1) having single source of truth - if you use traefik to route services, it's more reasonable to route everything from it, 2) single ssl point with automatic (optional) certificate request and renewal, 3) using more specialized software for the job, nginx is very nice but apart from being reverse proxy, it also manages web, caching, etc, while traefik is meant only for routing with optional middleware (also set up via single source of truth), 4) optional dashboard which allows to view set up routes and to a degree debug misconfigurationAzriel Gridfen

1 Answers

1
votes

Change:

- ./rules.yml:/etc/traefik/rules.yml

to:

- /etc/traefik/rules.yml:/etc/traefik/rules.yml

That should do it!

P.S. Thanks for the question; really enjoyed learning about Traefik and Keycloak!