How to setup Jupyter Server using Ubuntu

Requirements

  • nginx
  • supervisor
  • python

Nginx

sudo apt install nginx

Supervisor

sudo apt install supervisor

Jupyter

sudo apt install -y python3-pip
sudo apt install -y build-essential libssl-dev libffi-dev python3-dev

Jupyter

pip install jupyter

Generate jupyter config

cd ~
mkdir jup
jupyter notebook --generate-config

jupyter_notebook_config.py

c.NotebookApp.allow_remote_access = True
c.NotebookApp.base_project_url = '/username'
c.NotebookApp.notebook_dir = u'/home/username/jup'
c.NotebookApp.password = u'sha1:601185b5ebd2:aeda9a5adda03f6aec74a2830513f82ab59773b2'
c.NotebookApp.port = 8888
c.NotebookApp.port_retries = 50

Preparing a hashed password

Using python

from notebook.auth import passwd
passwd()

Enter password:

Verify password:

Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

Supervisor Config

[program:jup-username]
directory=/home/username/jup
user=username
command=jupyter notebook --no-browser --config=/home/username/.jupyter/jupyter_notebook_config.py
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stderr_logfile=/home/username/jup/logs/jup.err.log
stdout_logfile=/home/username/jup/logs/jup.log
redirect_stderr = true

Nginx

location /username {
    proxy_pass http://localhost: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;
}

References

  • https://towardsdatascience.com/host-a-jupyter-notebook-server-from-a-linux-vps-dd13c8570163
  • https://jupyter-notebook.readthedocs.io/en/stable/public_server.html#preparing-a-hashed-password

Victor Yoalli

This is me.