Jupyterhub does not start kernels neither terminals

I am trying to setup a jupyterhub with a nginx reverse-proxy within a docker container.

Here is my nginx configuration for jupytherhub:

location /jupyterhub {
            proxy_pass http://jupyterhub:8000/jupyterhub;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            # websocket headers
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header X-Scheme $scheme;

            proxy_buffering off;
        }

And here is the config for jupyterhub:

c.JupyterHub.bind_url = 'http://0.0.0.0:8000'
c.JupyterHub.port = 8000
c.JupyterHub.base_url = '/jupyterhub'
c.JupyterHub.authenticator_class = "dummy"
c.Authenticator.admin_users = {'admin_user'}

However, it seems that the kernel does not start correctly: it keeps trying to connect, but does not manage. I can also manage to open a terminal within jupyterhub, but then the terminal is stuck, see the screenshot below:

terminal

It seems to be related to the websockets, but I am not sure. I checked the jupyterhub logs and I don’t have any useful indication…

Many thanks!

Can you share more complete nginx config? Is it on a default port like 80 or 443, or is it on another port?

Did you check the logs of the single-user server? You might see errors like:

Blocking Cross Origin WebSocket Attempt.  Origin: http://localhost:8000, Host: localhost

I believe the issue is the use of $host in the config, which should be $http_host. I’ve just fixed this error in our docs.

Thanks for your answer!

I think my problem is more likely to come from my network (even if I still don’t know what exactly).

Just in case, here is a working nginx configuration file:

location /jupyterhub {
            proxy_pass http://jupyterhub:8000/jupyterhub;

            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            # websocket headers
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header X-Scheme $scheme;

            proxy_set_header Origin "";
        }

and for jupyterhub:

c.JupyterHub.bind_url = 'http://0.0.0.0:8000'
c.JupyterHub.port = 8000
c.JupyterHub.base_url = '/jupyterhub'
c.Spawner.args = [f'--NotebookApp.allow_origin={"*"}']
c.JupyterHub.tornado_settings = {
    'headers': {
        'Access-Control-Allow-Origin': '*',
    },
}
c.NotebookApp.trust_xheaders = True
c.NotebookApp.allow_origin = '*'