Jupyter Server
Jupyter Server deployment
Create
jupyterusersudo 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-configConfigure Jupyter
c.NotebookApp.ip = '*' c.NotebookApp.notebook_dir = '/home/jupyter/notebooks/' c.NotebookApp.open_browser = False c.NotebookApp.password = '' # hashed password c.NotebookApp.port = 9999Configure Apache:
<VirtualHost *:80> ServerName <DNS ENTRY> ServerSignature Off ErrorLog /var/log/apache2/redirect.error.log LogLevel warn ProxyPreserveHost On ProxyPass "/" "http://localhost:9999/" ProxyPassReverse "/" "http://localhost:9999/" RewriteEngine on RewriteCond %{SERVER_NAME} =<DNS ENTRY> RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName <DNS ENTRY> ServerSignature Off ErrorLog /var/log/apache2/redirect.error.log LogLevel warn ProxyPreserveHost On ProxyPass "/" "http://localhost:9999/" ProxyPassReverse "/" "http://localhost:9999/" <Location "/api/kernels/"> ProxyPass ws://localhost:9999/api/kernels/ ProxyPassReverse ws://localhost:9999/api/kernels/ </Location> SSLCertificateFile /etc/letsencrypt/live/<DNS ENTRY>/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/<DNS ENTRY>/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>Enable Apache modules
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod proxy_wstunnelGenerate SSL certs
sudo certbot --apache certonlyEnable the site
sudo a2ensite jupyter.conf && \ sudo systemctl reload apache2 && \ sudo systemctl status apache2Create 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.targetEnable the service
sudo systemctl daemon-reload && \ sudo systemctl start jupyter.service && \ sudo service jupyter status