Host a Jupyter Notebook Server From A Linux VPS | by Emmett Boudreau | Towards Data Science

Jupyter Notebooks are the industry standard tool for making programming far easier for statistical computing. This is because when programming statistics, you may often want to read returns and be able to edit and rerun code. Furthermore, having a virtual kernel to do so can also be incredibly useful. While Jupyter Notebooks are great to use on your local machine, it is hard to ignore that they run on an HTTP server. This is especially true given that Jupyter Notebooks is accessed through your web browser.
So since Jupyter Notebooks is made to run in a web browser, and features a full-fledged non-development server that even has password and write protection, it is easy to see why you might want to run Jupyter on a virtual private server (VPS.) Servers have gotten a lot cheaper to rent in recent years. Furthermore, you can get servers rented with far superior hardware to your computer quite easily. On top of that, it is a great way to share files, even text files, across a large team since you can even use Jupyter as a file browsing GUI, bash terminal, and text-editor.
Firstly, to get a web-server up and running on your VPS, you are of course going to have to SSH into that server.
ssh emmett@my-ip-is-hidden
In order to set up a web-server on Linux for wsgi, we’re going to need to have a web-server. I like to use NGINX, but there are several options out there, for example, Apache, which is also used often. However, if you are starting out I would highly suggest NGINX. NGINX is faster than Apache, and just as well I will be showing you how to set it up to host a local server in this article.
To use NGINX (It is pronounced engine-ex, by the way,) we will first need to install it. I am pretty sure NGINX is available in all package managers, but I certainly can’t account for man if you are using a Suse server.
sudo dnf install nginx
Once we have NGINX installed, we can move on to configuring our web-server. First, cd over to /etc/nginx/conf.d. This is where your NGINX configuration files are stored.
cd /etc/nginx/conf.d
Now open a new .conf file with Nano, make sure you run this as root, as it is likely you won’t have permissions to save files here:
sudo nano mysite.conf
Next, we’ll make a configuration file. If you don’t have any servers running on your VPS and you can use port 8000, then there is no shame or issue associated with copying mine:
server {    listen 80;    server_name your.ip.here;    location / {        proxy_pass http://127.0.0.1:8000;        proxy_set_header Host $host;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    }}
Now simply ctrl+o then press y to save the text buffer, and use ctrl+x to close Nano. Next, we will have to unlink the default NGINX configuration file.
sudo unlink /etc/nginx/sites-enabled/default
Now you can reload the configuration with:
nginx -s reload
To test your configuration, you can install and run jupyter-notebook, and then go to your domain or IP provided in the NGINX configuration file.
sudo dnf install jupyter-notebook && jupyter-notebook
Now if you navigate to your domain or IP in your web-browser, you should arrive in Jupyter.
The last step is to set up a supervisor to run the jupyter-notebook command. Depending on your distribution, you could need to install any of the following
sudo apt-get install supervisorsudo dnf install supervisord
Now we’ll cd over to our supervisor’s configuration directory.
/etc/supervisor/conf.d/
And now as you might have expected, we need to Nano up another configuration file.
Welcome to the world of dev-ops.
Here is mine, which you can use to base yours off of.
[program:flask_app]directory=/command=jupyter-notebookautostart=trueautorestart=truestopasgroup=truekillasgroup=truestderr_logfile=/var/log/appname/lognameerr.logstdout_logfile=/var/log/appname/lognamestdout.log
Easy, right?
Now just reload Supervisor,
sudo service supervisor reload
And now your notebook server will be up, and you can visit and use it along with anyone else at any time!
I think that having your own Jupyter Notebook server that is remote is really cool! It is one of the better ways I have used to work in a team, as your entire team could be accessing and modifying files in the same directory together at the same time. Furthermore, you will have access to Bash, Notebooks, and a graphical text editor. While I certainly love Nano, I can see why it might be a little daunting for those who aren’t terminal maniacs like myself. You could also use this as a local solution for network attached storage, especially if you intend to keep all your data-science projects in there. This is a great way to get use out of an old computer by essentially turning it into a server. All in all, it is hard to not find a great use for a Jupyter server whether local, on a VPS, NAS, or even running on your laptop from the early 2000s with 2GB of RAM.