Jupyterlab nginx reverse proxy at subpath causing ServerApp 404 GET /api error

I’m trying to set up jupyter lab behind an nginx reverse proxy on the subpath /jlab

Here’s my minimal example:

docker-compose.yml

version: "3.7"
services:
  nginx:
    image: nginx:alpine
    volumes:
      - "./default.conf:/etc/nginx/conf.d/default.conf:ro"
    ports:
      - 8080:80
    links:
      - "jupyterlab"
  jupyterlab:
    image: jupyter/scipy-notebook
    container_name: jupyterlab
    volumes:
      - "./jupyter_server_config.py:/home/jovyan/.jupyter/jupyter_server_config.py:ro"

default.conf

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location /jlab {
        proxy_pass http://jupyterlab:8888;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
    }
}

jupyter_server_config.py

c.ServerApp.allow_remote_access = True
c.ServerApp.allow_root = True
c.ServerApp.base_url = '/jlab'
c.ServerApp.ip = '*'
c.ServerApp.token = u''

This can be run with docker compose up --build -d
jupyterlab can now be reached at localhost:8080/jlab
Everything appears to be working. But if you look at the logs you get this repeated message:

jupyterlab    | [W 2022-08-06 00:18:27.783 ServerApp] 404 GET /api (127.0.0.1) 1.04ms referer=None

The status of the container turns to Up About a minute (unhealthy), so I’m guessing this will be a problem, but I’m not sure what the problem is or how to fix it.

This is due to the HEALTHCHECK in

I think this HEALTHCHECK is worth mentioning in the docs as it’s come up a few times before. The docs are https://jupyter-docker-stacks.readthedocs.io/ and the repo is GitHub - jupyter/docker-stacks: Ready-to-run Docker images containing Jupyter applications if you want to open an issue or a PR!

Just to close the loop, adding the environment variable to the jupyterlab section of the docker-compose file fixes the issue identified by @manics:

  jupyterlab:
    image: jupyter/scipy-notebook
    container_name: jupyterlab
    volumes:
      - "./jupyter_server_config.py:/home/jovyan/.jupyter/jupyter_server_config.py:ro"
    environment:
      - "JUPYTERHUB_SERVICE_PREFIX=/jlab/"

:partying_face:

1 Like