Jupyter Server
Jupyter Server deployment
Create
jupyter
usersudo adduser jupyter && \ sudo usermod -a -G staff jupyter sudo su jupyter && \
Install Jupyter Lab
source /home/jupyter/.venv/bin/activate && \ python -m pip install jupyterlab && \ jupyter-lab --generate-config
Configure Jupyter
= '*' c.NotebookApp.ip = '/home/jupyter/notebooks/' c.NotebookApp.notebook_dir = False c.NotebookApp.open_browser = '' # hashed password c.NotebookApp.password = 9999 c.NotebookApp.port
Configure Apache:
<VirtualHost *:80> <DNS ENTRY> ServerNameServerSignature Off /var/log/apache2/redirect.error.log ErrorLogLogLevel warn ProxyPreserveHost On "/" "http://localhost:9999/" ProxyPass "/" "http://localhost:9999/" ProxyPassReverse RewriteEngine on %{SERVER_NAME} =<DNS ENTRY> RewriteCond ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] RewriteRule</VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> <DNS ENTRY> ServerNameServerSignature Off /var/log/apache2/redirect.error.log ErrorLogLogLevel warn ProxyPreserveHost On "/" "http://localhost:9999/" ProxyPass "/" "http://localhost:9999/" ProxyPassReverse <Location "/api/kernels/"> ws://localhost:9999/api/kernels/ ProxyPass ws://localhost:9999/api/kernels/ ProxyPassReverse</Location> /etc/letsencrypt/live/<DNS ENTRY>/fullchain.pem SSLCertificateFile /etc/letsencrypt/<DNS ENTRY>/privkey.pem SSLCertificateKeyFile /etc/letsencrypt/options-ssl-apache.conf Include</VirtualHost> </IfModule>
Enable Apache modules
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod proxy_wstunnel
Generate SSL certs
sudo certbot --apache certonly
Enable the site
sudo a2ensite jupyter.conf && \ sudo systemctl reload apache2 && \ sudo systemctl status apache2
Create the Jupyter service:
/lib/systemd/system/jupyter.service
# service name: jupyter.service # path: /lib/systemd/system/jupyter.service [Unit] Description=Jupyter Notebook Server [Service] Type=simple PIDFile=/run/jupyter.pid ExecStart=/bin/bash -c "/home/jupyter/.venv/bin/jupyter lab --no-browser" User=jupyter Group=staff WorkingDirectory=/home/jupyter/notebooks Restart=always RestartSec=30 [Install] WantedBy=multi-user.target
Enable the service
sudo systemctl daemon-reload && \ sudo systemctl start jupyter.service && \ sudo service jupyter status