JupyterHub in Docker and Nginx on host: kernel problem

Hello,

I tried to setup a dockerized JupyterHub and access it through Nginx reverse-proxy on the host.
But, alas kermels are not functionals.

If the same docker container is bound directly to an open port of the host, everything is ok.
If the same docker container is bound to a non open port, but I create an ssh tunnel to access it, everything is ok.

So, I deduced that something goes wrong with Nginx.
The hub should be accessible through MY_HOST/something.
So basically my Nginx config is:

    listen [::]:80;
    listen 80;
    server_name MY_HOST;

    root /var/www/dummy;

    access_log on;
    access_log /var/log/nginx/MY_HOST.access.log;
    error_log /var/log/nginx/MY_HOST.error.log error;

    location / {
        return 301 /something/;
    }

    location /something/ {
        proxy_pass http://127.0.0.1:50000/something/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass_request_headers on;
        proxy_pass_header Set-Cookie;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Cookie $http_cookie;
    }

jupyterhub_config.py contains only:

c.JupyterHub.bind_url = 'http://:8000/something/'
c.Spawner.default_url = '/lab'

Docker is bound with 50000 → 8000

Symptom: users can connect, kernels are available, but executing a cell does not work, and terminal is not functional too.

What’s wrong? Looks like some data can’t pass (which way) through Nginx? Cookie? Missing port? Path?

The previous symptom was that a message like “Kernel load failed” appeared, but removing some Nginx config lines, filtering some requests (not GET, HEAD, POST) made this message disappearing. This is why I suspect my nginx behaving wrongly.

Best, JB

It looks like you’re missing the websockets config for Nginx. If you open your browser console you should see some websocket errors. Have a look at the Nginx config from the docs:

Ho! Thanks! I forgot it, stupid I am. Works well now.

1 Like