You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker中通过Traefik为JupyterLab添加路径前缀的路由配置问题

问题解决:Docker下Traefik配置JupyterLab路径前缀

问题根源

你当前的配置矛盾在于:JupyterLab已经通过--NotebookApp.base_url=/user设置了自身的路径前缀,此时它会在/user路径下响应请求,但Traefik的StripPrefix中间件却把请求的/user前缀剥离了,导致转发到JupyterLab的请求路径变成了/,而JupyterLab并没有在根路径提供服务,因此无法访问。

修改后的docker-compose.yml配置

version: "3.8"

services:
  reverse-proxy:
    image: traefik:v2.4
    command: --api.insecure=true --providers.docker # --log.level=DEBUG
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - traefik.enable=false

  jupyter_rewrite_path:
    restart: always
    image: jupyter/scipy-notebook
    command: jupyter-lab --ip='*' --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.base_url=/user
    labels:
      - traefik.http.routers.jupyter_rewrite_path.rule=Host(`jupyter-test.localhost`) && PathPrefix(`/user`)
      - traefik.http.services.jupyter_rewrite_path.loadbalancer.server.port=8888
      # 移除StripPrefix中间件,因为JupyterLab已处理base_url

关键调整说明

  • 完全移除了StripPrefix相关的中间件配置,Traefik会直接将匹配/user前缀的请求转发给JupyterLab。
  • JupyterLab的base_url=/user已经让服务自身在/user路径下处理所有请求,转发时不需要修改路径,两者路径匹配后即可正常访问。

验证方法

执行docker-compose up启动服务后,访问http://jupyter-test.localhost/user即可正常进入JupyterLab界面。

内容的提问来源于stack exchange,提问作者ctappy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 11:30:59