I have access to a single subdomain, subdomain.domain.com, on which I run several services behind traefik. In order to route the requests to the right server, I am setting the traefik router rules to distinguish the PathPrefix.
JupyterHub is one of the services I am running, which I am trying to run in "subdomain.domain.com/jupyterhub". By setting c.JupyterHub.bind_url="http://:8000/jupyterhub", I can have JuptyerHub work that way. But the servers it spawns with the dockerspawner are still running on "/user/{username}", and not on "/jupyterhub/user/{username}". I figure it must be a JupyterLab option I have to set, but I cannot figure out how.
My setup (relevant sections):
docker-compose.yaml:
version: '3.5'
services:
jupyterhub:
build: ./jupyterhub
expose:
- 8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./jupyterhub/ssl.crt:/srv/jupyterhub/ssl.crt
- ./jupyterhub/ssl.key:/srv/jupyterhub/ssl.key
- /etc/hostname:/srv/jupyterhub/host_hostname:ro
networks:
- traefik_proxy
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik_proxy"
- "traefik.http.services.jupyterhub.loadbalancer.server.port=8000"
- "traefik.http.services.jupyterhub.loadbalancer.server.scheme=https"
- "traefik.http.routers.jupyterhub.entrypoints=websecure"
- "traefik.http.routers.jupyterhub.rule=Host(`subdomain.domain.com`) && (PathPrefix(`/jupyterhub`) || PathPrefix(`/hub`) || PathPrefix(`/user`))"
- "traefik.http.routers.jupyterhub.tls=true"
- "traefik.http.routers.jupyterhub.middlewares=strip-jupyterhub@docker"
- "traefik.http.middlewares.strip-jupyterhub.stripprefix.prefixes=/jupyterhub"
jupyterhub/Dockerfile:
FROM jupyterhub/jupyterhub:1.3.dev
RUN apt-get update && apt-get -y install sssd gcc python3-dev
RUN pip install dockerspawner oauthenticator PyJWT netifaces
ADD jupyterhub_config.py /srv/jupyterhub
jupyterhub/jupyterhub_config.py:
<snip>
c.DockerSpawner.image = 'jupyter/datascience-notebook:lab-2.1.1'
c.JupyterHub.bind_url = 'http://:8000/jupyterhub/'
<snip>
This setup works, but only because I have added the PathPrefix(/user
) in the traefik rule and I am stripping '/jupyterhub/' from the URL using traefik middleware. The JupyterHub spawner redirects everything to 'subdomain.domain.com/user/{username}', and I don't know how to run it on 'subdomain.domain.com/jupyterhub/user/{username}'.