Jupyter Notebook and Nginx Setup

本文介绍了Jupyter笔记本的功能及用途,包括数据处理、数值模拟等,并提供了安装指南及如何设置Notebook服务器的方法。还详细讲解了如何在Ubuntu环境下使Jupyter后台运行,以及如何配置Nginx服务器来优化客户端交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


The Jupyter Notebook is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more.

Jupyter project had a long history of development, It started with the Ipython project which provides a rich set of tools for computing and visualization with Python at it’s core. In the recent years the Ipython project broke into small components and the Kernel is the core of Jupyter.

Jupyter supports multiple programming languages.

For more information click here

Jupyter Installation

I would suggest installing from continuum anaconda project. It provides a seemless package management and virtual env setup tool. And also provides a rich set of libraries bundled with the setup. You can find the instruction here

Setting up the Notebook Server

You can start the notebook server as:


 
1
2
3
jupyter notebook
#for all the args
jupyter notebook --help-all

The Notebook is a Python tornado Server which serves the Terminal and kernel UI.

Demonizing the Notebook Server For Ubuntu


 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
touch /etc/init/yourupstartjobname.conf
#content for your Upstart file
description "Service for jupyter notebook"
author      "You"

start on filesystem or runlevel [2345]
stop on shutdown
respawn

script
    echo $$ > /var/run/jupyter.pid
    exec /pathto/anaconda3/bin/jupyter notebook --no-browser 
    --NotebookApp.allow_origin='*' --notebook-dir='/pathtoworkspace'

end script

pre-stop script
    rm /var/run/jupyter.pid
end script

Setting Up Nginx server

As the Notebook server runs On Tornado which uses the websockets for some part of the Client Interaction. Standard nginx proxy pass uses the Http protocal. So we need to add some configuration to work.

For Interacting with the Terminal and And Kernel it uses the WSS(websocket protocal). You can find more about this here

Heres My Nginx configuation.


 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
upstream notebook {
    server localhost:8888;
}
server{
listen 80;
server_name xyz.abc.com;
location / {
        proxy_pass            http://notebook;
        proxy_set_header      Host $host;
}

location ~ /api/kernels/ {
        proxy_pass            http://notebook;
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }
location ~ /terminals/ {
        proxy_pass            http://notebook;
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
}
}

NOTE: If you are using Apache Server or AWS ELB you need similar kind of tweaks to work for you.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值