Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traefik Reverse Proxy to external Server

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"
like image 743
Tobias Benkner Avatar asked Apr 04 '20 17:04

Tobias Benkner


1 Answers

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!

like image 106
Dan M Avatar answered Sep 26 '22 20:09

Dan M