Programming Tutorials

How to install Jupyter in Ubuntu and make it accessible through Apache Reverse Proxy

By: Suresh in Python Tutorials on 2019-02-23  

Jupyter Notebooks have become the defacto standard for data scientists to show case their research and machine learning algorithms and work for presentation and sharing with others. Here we can see how to make Jupyter Notebooks to be accessed over internet from our server.

As usual start with updating ubuntu repositories and upgrade to latest

sudo apt update
sudo apt -y upgrade

If you have not installed python already, you install it now. Otherwise skip this part.

sudo apt-get install python3.6
sudo apt install -y python3-pip

Also install the necessary development tools

sudo apt install build-essential libssl-dev libffi-dev python3-dev

Create a virtual configuration in apache2 as below


        ServerName      jupyter.yourdomain.com
        ProxyPreserveHost On
        ProxyRequests off

        ProxyPass /api/kernels/ ws://localhost:8888/api/kernels/
        ProxyPassReverse /api/kernels/ http://localhost:8888/api/kernels/

        ProxyPass       / http://localhost:8888/
        ProxyPassReverse        / http://localhost:8888/

In addition to enable apache reverse proxy, you also need to enable wstunnel

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel

sudo systemctl restart apache2

Now that you have restarted apache2, you can start jupyter to run in the background using screen

apt-get install screen

screen -A -m -d -S jup jupyter notebook --allow-root --no-browser --NotebookApp.allow_remote_access=True

The switch --NotebookApp.allow_remote_access=True is important to allow the access of notebooks over internet. This will avoid errors such as this" Blocking request with non-local 'Host' jupyter.yourdomain.com. If the notebook should be accessible at that name, set NotebookApp.allow_remote_access to disable the check.

Also if you are not familiar with screen, you should probably google around to check how to use it. Some common commands are:

#to list all the screens
screen -ls

#to view the screen interface
screen -r

#to come out and detach from screen view
ctrl + A
and then
D





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Python )

Latest Articles (in Python)