How to run Keycloak on a domain?

387 views
Skip to first unread message

DP

unread,
Apr 21, 2023, 6:40:31 AM4/21/23
to Keycloak User
Hi!

I want to run a Keycloak instance so that it is available via http://myproduct.local. For now I want to try it out locally.

To do this, I wrote the following NGINX configuration file:

START

server {
  listen 80;
  server_name myproduct.local;

  location /keycloak {
    proxy_pass http://host.docker.internal:8103/;
  }


  location / {
    proxy_pass http://host.docker.internal:8081;
  }
}
}


END

Then, I launch Nginx and Keycloak using the following docker-compose.yaml file:

START

version: '3.7'

services:
  router:
    image: nginx:1.23.3
    ports:
     - 80:80
    volumes:
      - ./site.conf:/etc/nginx/conf.d/site.conf

  app-x:
    image: app-x
    ports:
     - 8081:80

  app-y:
    image: app-y
    ports:
     - 8082:80

  app-z:
    image: app-z
    ports:
     - 8083:80

  keycloak:
    container_name: keycloak-2
    image: quay.io/keycloak/keycloak:20.0.1
    ports:
      - "8103:8080"
      - "443:8443"
    environment:
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
    command:
      - start-dev --hostname=http://myproduct.local/keycloak


END

The "router" uses the site.conf file shown above.

When I open the URL http://myproduct.local/keycloak in the browser,

a) the images, styles etc. are not present on the page and

b) I cannot access the admin console (I am redirected to http://host.docker.internal:8103/admin/ ).
Screenshot 2023-04-21 at 13.35.20.png


What do I need to change in the site.conf and/or docker-compose.yaml file in order to fix these issues?

Thanks in advance
Message has been deleted

Jannik

unread,
Apr 21, 2023, 10:36:19 AM4/21/23
to keyclo...@googlegroups.com
Hi, if I remember correct the nginx configuration
needs a few headers set for this to work.

server { 
    listen       8000; 
    server_name  localhost; 
  
    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://backend
    } 
}

I think you can just give it a try.

Regards,

networksecurityvodoo
Reply all
Reply to author
Forward
0 new messages