How to install jupyter notebook on ubuntu 20.04
Base environment:
➜ ~ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
➜ ~ python --version
Python 3.8.5
➜ ~ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
➜ ~ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
Installing Jupyter
pip install jupyter
jupyter jupyter notebook --generate-config
vim /home/zhangyuqing/.jupyter/jupyter_notebook_config.py
add the hostname of nginx
# allow requests from your domain (works in combo with $http_host from NGINX)
c.NotebookApp.local_hostnames = ['localhost','jupyter.n5.box']
change the http port
c.NotebookApp.port = 7788
Systemd Service
sudo vim /lib/systemd/system/jupyter.service
[Unit]
Description=Jupyter Management
After=network.target
[Service]
User=zhangyuqing
Group=zhangyuqing
WorkDirectory=/home/notebook/
ExecStart=/usr/local/bin/jupyter notebook
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable jupyter.service
sudo systemctl start jupyter.service
sudo systemctl status jupyter.service
Nginx Settings
sudo vim /etc/nginx/sites-enabled/jupyter
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
listen [::]:80;
server_name jupyter.n5.box;
location / {
proxy_pass http://localhost:7788;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
sudo systemctl restart nginx.service
Jupyter Password
jupyter notebook password