Jupyter Notebook
安装Jupyter
假定工作目录为/home/jupyter
| 12
 3
 
 | $ virtualenv venv -p python3$ source venv/bin/activate
 $ (venv) pip install jupyter
 
 | 
配置Jupyter
安装Jupyter之后,在~/.jupyter下查看是否存在jupyter_notebook_config.py文件,如果没有,就使用
| 1
 | $ (venv) jupyter notebook --generate-config
 | 
命令生成配置文件,Jupyter的具体配置内容参见Jupyter Notebook的配置选项,下边的几个选项是为部署在服务器上可能要用到的(下边c.NotebookAPP.password的设置方法见Jupyter Notebook添加密码)
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
 | c.NotebookApp.allow_origin = '*'
 
 c.NotebookApp.allow_password_change = False
 
 c.NotebookApp.allow_remote_access = True
 
 c.NotebookApp.base_url = '/python'
 
 c.NotebookApp.default_url = '/python/tree'
 
 c.NotebookApp.ip = '127.0.0.1'
 
 c.NotebookApp.notebook_dir = 'data/'
 
 c.NotebookApp.open_browser = False
 
 c.NotebookApp.password = 'sha1:******'
 
 c.NotebookApp.port = 8888
 
 | 
集成 Nginx
Jupyter Notebook使用tornado作为服务器和Web框架,如果想要获取更高的性能以及灵活性,可以使用Nginx作为代理服务器。在/etc/nginx/conf.d/jupyter.conf中添加以下内容:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 
 | server {listen 80 default_server
 server_name myjupyter.com
 charset     utf-8
 client_max_body_size    75M
 
 location /python/ {
 
 proxy_pass http://127.0.0.1:8888/python/
 proxy_set_header X-Real-IP $remote_addr
 proxy_set_header Host $host
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for
 proxy_http_version 1.1
 proxy_set_header Upgrade $http_upgrade
 
 proxy_set_header Connection "upgrade"
 proxy_redirect off
 }
 }
 
 | 
配置完成之后,启动Jupyter Notebook即可远程访问
| 12
 3
 4
 
 | $ (venv) jupyter notebook
 
 $ (venv) nohup jupyter notebook &
 
 | 
此时在浏览器输入http://myjupyter.com/python即可进入Jupyter Notebook。