We assume that JupyterLab is already installed.

1. Configure JupyterLab/Hub

  1. Generate jupyter_notebook_config.py file:

     $ jupyter notebook --generate-config
    
  2. Edit jupyter_notebook_config.py

  • Change base_url:

      c.NotebookApp.base_url = '/jlab'
    
  • Change allowed hostnames:

      c.NotebookApp.local_hostnames = ['localhost', 'hostname.com']
    

2. Start Jupyter automatically

We’ll start Jupyterlab on port 8888. Change the directories according to your installation.

  • Create script:

      vi ~/start-jupyter.sh
    

    Content:

      #!/bin/bash
    
      /home/user/miniconda3/envs/jup/bin/jupyter-lab \
              --notebook-dir=/home/user \
              --port=8888 \
              --ContentsManager.allow_hidden=True \
              --no-browser
    
  • Add new service:

      vi /etc/systemd/system/jupyter.service
    

    Content:

      [Unit]
      Description=Jupyter Notebook
    
      [Service]
      Type=simple
      PIDFile=/run/jupyer.pid
      ExecStart=/home/user/start-jupyter.sh
      User=user
      Group=group
      Restart=always
      RestartSec=30
    
      [Install]
      WantedBy=multi-user.target                 
    
  • Start service

      sudo service jupyter enable
      sudo service jupyter start
    

3. Configure OpenLiteSpeed (OLS)

No need to use rewrite rules here. Select your site on OpenLiteSpeed panel and add the following:

  1. External App
    • Type: Web Server
    • Name: jupyter
    • Address: localhost:8888
    • Max Connections: 5 external app
  2. Context Use the same base_url as above.
    • Type: Proxy
    • URI: /jlab
    • Web Server: select name from step above context
  3. Web Socket Proxy. This is required for the kernel connection.
    • URI /jlab
    • Address: localhost:8888
  4. Restart OLS

Restart Python process (wsgi)

killall lswsgi

Fix permission issues:

chown -R nobody:nogroup /usr/local/lsws/Example/html/demo