Jupyter Notebook Server for Single User

Steps

  • A notebook configuration file
# generate a configuration file
$ jupyter notebook --generate-config

# the default configuration path
$ vim /home/(user)/.jupyter/jupyter_notebook_config.py
  • Automatic Password setup
# start python
$ python
# import the library
from notebook.auth import passwd

# generate SHA-1 password
# for exmaple: u'sha1:xxx:yyy'
passwd()
  • Adding hashed password to your notebook configuration file
# edit the configuration
$ vim /home/(user)/.jupyter/jupyter_notebook_config.py
# edit the password item
c.NotebookApp.password = u'sha1:xxx:yyy'
  • Running a public notebook server
# edit the configuration
$ vim /home/(user)/.jupyter/jupyter_notebook_config.py
# Set options for certfile, ip, password, and toggle off browser auto-opening
# if the certfile and keyfile is not set, jupyter notebook would be run over http protocol
c.NotebookApp.certfile = u'/etc/letsencrypt/live/example.com/cert.pem'
c.NotebookApp.keyfile = u'/etc/letsencrypt/live/example.com/privkey.pem'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:xxx:yyy'
c.NotebookApp.open_browser = False

# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 8899
  • [optional for proxy_pass] Running the notebook with a customized URL prefix
$ vim /home/(user)/.jupyter/jupyter_notebook_config.py
# the new url is http(s)://xxx:8888/jupyter
c.NotebookApp.base_url = '/jupyter/'
c.NotebookApp.webapp_settings = {'static_url_prefix':'/jupyter/static/'}
  • Establish the execution script.
# create a shell script
$ vim /home/(user)/anaconda3/jupyternotebook.sh
#!/bin/bash
/home/(user)/anaconda3/bin/jupyter notebook
# add execution property to the script
$ chmod a+x /home/(user)/anaconda3/jupyternotebook.sh
  • Establish the service.
# create a new service
$ sudo vim /etc/systemd/system/jupyternotebook.service
[Unit]
Description=jupyter notebook server
After=network.target

[Service]
User=(user)
Group=(user)
ExecStart=/home/(user)/anaconda3/jupyternotebook.sh
Restart=always
WorkingDirectory=/home/(user)/(path)

[Install]
WantedBy=multi-user.target
sudo systemctl start jupyternotebook.service
sudo systemctl status jupyternotebook.service
sudo systemctl enable jupyternotebook.service
  • Start the service.
<!-- surf the link -->
http(s)://example.com:8888/jupyter

Server Configuration

  • Nginx
$ sudo vim /etc/nginx/sites-available/default
server {
    listen 80;
    server_name example.com;

    charset     utf8;
    access_log    /var/log/nginx/jupyter.access.log;

    location /jupyter/ {
        proxy_pass http://127.0.0.1:8899/jupyter/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # web socket
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
}
# reload the configuration
$ sudo systemctl reload nginx

results matching ""

    No results matching ""