一、安装jupyter
pip3 install jupyter
二、配置jupyter
jupyter notebook --generate-config # 初始化一个jupyter配置文件
创建的配置文件位置在/home/{user}/.jupyter/jupyter_notebook_config.py,需要做以下配置:
# 使用vim或其他编辑器编辑配置文件
vim /home/{user}/.jupyter/jupyter_notebook_config.py
# 在配置文件中添加下面内容
c.NotebookApp.base_url = '/jupyter/' # prefix,供nginx反代时使用
c.NotebookApp.ip='0.0.0.0' # 因为要远程访问,IP设为0.0.0.0。
c.NotebookApp.open_browser = False # 启动jupyter notebook时不启动浏览器
c.NotebookApp.port =8888 # 可自行指定一个端口, 访问时使用该端口
c.NotebookApp.allow_remote_access = True # 允许远程访问
# 保存退出
三、配置nginx反代jupyter
在nginx的配置文件中(通常nginx的配置文件的位置在/etc/nginx/conf.d/default.conf)加入以下内容:
# 编辑ngnix的配置文件
vim /etc/nginx/conf.d/default.conf
# 在server内添加以下内容
location /jupyter {
proxy_pass http://{ip或域名}:8888;
proxy_set_header Host master;
proxy_set_header X-Real-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_next_upstream error;
}
保存退出
四、启动jupyter notebook并重启nginx
# 启动jupyter notebook
jupyter notebook
# 为安全及方便起见设置密码
jupyter notebook password
# 重启nginx
service nginx restart
五、远程通过浏览器访问jupyter notebook的地址(http://域名或IP/jupyter)输入密码即可进入

登录jupyter notebook

进入jupyter notebook

我的微信
有问题微信找我