0. 概述
在以前,我都是在本地开发机上运行 jupyter,但是,这在重启机器的时候和在不同开发机的情况下显得有点尴尬,为了方便,于是乎我就将 jupyter 架设在远程服务器上,本文就介绍一下我的架设过程。
1. 创建运行环境
[[email protected]]# python36 -m virtualenv venv36
Using base prefix '/usr'
New python executable in /root/soft/jupyter/venv36/bin/python36
Also creating executable in /root/soft/jupyter/venv36/bin/python
Installing setuptools, pip, wheel...done.
[[email protected]]# source venv36/bin/activate
[[email protected]]# pip install jupyter
2. 配置 jupyter
[[email protected]]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
[[email protected]]# python -c "from notebook.auth import passwd; print(passwd())"
Enter password:
Verify password:
sha1:sdfasd:abcsdfasdfasdfasdf
[[email protected]]# vim /root/.jupyter/jupyter_notebook_config.py
图 1:设置 jupyter 密码 |
---|
3. 运行 jupyter
[[email protected]]# jupyter notebook
[I 22:42:58.254 NotebookApp] Serving notebooks from local directory: /root/soft/jupyter
[I 22:42:58.255 NotebookApp] The Jupyter Notebook is running at:
[I 22:42:58.255 NotebookApp] http://localhost:8888/
[I 22:42:58.255 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
4. 配置 Nginx 代理
[[email protected]]# cat /root/.jupyter/jupyter_notebook_config.py | grep base
## The base URL for the notebook server.
c.NotebookApp.base_url = '/jupyter'
[[email protected]]# cat /etc/nginx/jupyter.conf
location /jupyter {
proxy_pass http://127.0.0.1:8888;
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;
}
然后重新加载 Nginx 配置,Enjoy。