Back

JupyterHub configuration for a Data Science course on Ubuntu 20.04 Server

This is the current server setup I use for creating a virtual multi user python environment for my data science courses. I use JupyterHub on a Ubuntu 20.04 server. I'll describe how to configure a reverse proxy on apache httpd too.

Prerequisites

Before installing JupyterHub, you will need:

- a Linux/Unix based system

- Python 3.5 or greater. An understanding of using pip or conda for installing Python packages is helpful.

- nodejs/npm. Install nodejs/npm, using your operating system’s package manager.

If you are using conda, the nodejs and npm dependencies will be installed for you by conda.

If you are using pip, install a recent version of nodejs/npm. For example, install it on Linux (Debian/Ubuntu) using:

sudo apt-get install npm nodejs-legacy


The nodejs-legacy package installs the node executable and is currently required for npm to work on Debian/Ubuntu.

Install JupytherHub

JupyterHub can be installed with pip (and the proxy with npm) or conda:

pip, npm:

python3 -m pip install jupyterhub
npm install -g configurable-http-proxy
python3 -m pip install notebook  # needed if running the notebook servers locally

or use The Little Jupyter Hub (TLJH), this was my choice because i get some extra stuff already configured like startup script for systemd and the tljh-config tool to configure the installation:

curl -L https://tljh.jupyter.org/bootstrap.py | sudo -E python3 - --admin <admin-user-name>

Configuration

Configure the port to 9999:

sudo tljh-config set http.port 8080

Install modules for apache2 needed for the proxy:

a2enmod ssl rewrite proxy proxy_http proxy_wstunnel


Configure the reverse proxy in apache2:

<VirtualHost _default_:443>
        ServerName jupyter.test.com
        ServerSignature Off

        Include /etc/letsencrypt/options-ssl-apache.conf

        SSLCertificateFile /etc/letsencrypt/live/jupyter.test.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/jupyter.test.com/privkey.pem

        RewriteEngine On
        RewriteCond %{HTTP:Connection} Upgrade [NC]
        RewriteCond %{HTTP:Upgrade} websocket [NC]
        RewriteRule /(.*) ws://127.0.0.1:9999/$1 [P,L]

        <Location "/">
                # preserve Host header to avoid cross-origin problems
                ProxyPreserveHost on
                # proxy to JupyterHub
                ProxyPass         http://127.0.0.1:9999/
                ProxyPassReverse  http://127.0.0.1:9999/
        </Location>

        ErrorLog ${APACHE_LOG_DIR}/jupyter_test_error.log
        CustomLog ${APACHE_LOG_DIR}/jupyter_test_access.log combined

</VirtualHost>

Create a new admin user:

sudo tljh-config add-item users.admin <username>
sudo tljh-config reload

Have fun with your new JupyterHub installation!

Get in touch_