Setting up jupyter lab behind a reverse proxy (nginx)

From Media Design: Networked & Lens-Based wiki
Revision as of 17:53, 27 January 2021 by Michael Murtaugh (talk | contribs) (Created page with "How to reverse proxy jupyter: On your /etc/nginx/sites-available/default where 9068 is the port you have configured... jupyter <code> server { ... location ^~...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How to reverse proxy jupyter:

   On your /etc/nginx/sites-available/default

where 9068 is the port you have configured... jupyter

server {

   ...
      location ^~ /__lab__/ {
           proxy_pass http://localhost:9068/;
           # include /etc/nginx/includes/lab.conf;
           # this line is only useful for the sandbox!
           rewrite /(.*) /sandbox/$1  break;
           error_page 502 /lab/502.html;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header Host $http_host;
           proxy_http_version 1.1;
           proxy_redirect off;
           proxy_buffering off;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           proxy_read_timeout 86400;
       }

Generate a jupyter password "hash", in python (3) ...

python
from IPython.lib import passwd
print(passwd("yourspecialpassword"))

In a (new) jupyter config file:

 nano ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.base_url = '/__lab__/'
c.NotebookApp.port =9068
c.NotebookApp.trust_xheaders = True
c.NotebookApp.port_retries = 0
c.NotebookApp.password = 'password_hash_from_python_above'
c.NotebookApp.allow_remote_access = True