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.


  • 安装Miniconda
  • 安装Ipython或Jupyter
  • 配置Jupyter notebook配置文件
  • 配置nginx
  • Jupyterthemes
  • Ipython notebook常用配置

安装Miniconda

Miniconda是什么?自己google.
Miniconda下载地址

安装64位的python3.6

$ wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh | bash Miniconda3-latest-MacOSX-x86_64.sh

安装Ipython和Jupyter

$ conda update conda
$ conda install ipython
$ conda install jupyter

配置Jupyter notebook配置文件

生成配置文件
$ jupyter notebook --generate-config

配置密码
打开Ipython,创建一个密码

>>> from notebook.auth import passwd
>>>passwd()
Enter password:  
Verify password:  
Out[2]: 'sha1:6e8a2a94cfaf:8f832ec0ae0dc5bc6477ef6bb32ccc76fa1394df'  

编辑配置文件
$ vim ~/.jupyter/jupyter_notebook_config.py

配置文件都是注释的,在最后面添加几行就行了

# 利用nginx反向代理
c.NotebookApp.ip='127.0.0.1'  
# 上面获得的sha密码
c.NotebookApp.password = u'sha1:6e8a2a94cfaf:8f832ec0ae0dc5bc6477ef6bb32ccc76fa1394df'  
# 不打开浏览器
c.NotebookApp.open_browser = False  
# 指定端口
c.NotebookApp.port =8888  
# 启动默认文件夹,这里是家目录下的notebook文件夹
c.NotebookApp.dir = 'notebook'  

配置Nginx反代

PS:网上的教程一般到这就没了,都是本地调试的,很多都是一样的,但并没有什么用.

Jupyter Notebook需要ssl传输数据的,所以域名必须要有ssl证书,因为我的ssl证书是泛域名的,所以就配置了一个二级的域名这里以https://ipython.senlief.com为例.

新建一个nginx配置文件

# vim /etc/nginx/conf.d/jupyter.conf

写入下面的配置文件内容,注意对应修改

server {  
    listen       443 ssl;
    server_name  ipython.senlief.com;

#    resolver             8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=300s;
#    resolver_timeout     10s;

    ssl                  on;
    ssl_certificate      /etc/senlief.pem; # 证书对应的路径
    ssl_certificate_key  /etc/senlief.key; # 证书对应的key路径

    ssl_session_cache shared:SSL:20m;
    ssl_session_timeout  10m;

    ssl_prefer_server_ciphers   on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers  HIGH:!aNULL:!MD5;

    add_header Strict-Transport-Security "max-age=31536000; preload";
    error_page 404 =https://senlief.com/404.html;
#includeSubdomains
    location / {
#        proxy_set_header   X-Real-IP $remote_addr;
    proxy_redirect     off;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_http_version 1.1;
        proxy_set_header   Connection "Upgrade";
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:8888;
#        proxy_read_timeout 86400;
    }
}     

Jupyter notebook采用的是websocket链接,下面的配置中必须配置对应的header信息,要不然会一直报错 A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration.
可以利用debug来调试信息.
$ jupyter notebook --debug
这样就可以通过ipython.senlief.com访问了

Notebook主题设置

主题
$ pip install --upgrade jupyterthemes

设置monokai主题

jt -t monokai -nfs 12

相关配置后续