当服务器配置好 Python, Jupyterlab 后,访问总是通过 8888 端口,出于某些原因,想要为其配置二级页面,这样当想要更改端口时只需要修改一下配置,而不需要再次记忆到底是打开了哪个端口,只需要记住二级页面 web 地址就可以。本篇不介绍如何配置 Jupyterlab,而是假设已经配置好了 Jupyterlab,且申请了域名,直接说如何通过 nginx 配置 Jupyterlab.
安装 nginx
1 2 3 4 5
| sudo apt update sudo apt install nginx sudo systemctl status nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
|
配置 Jupyterlab
1 2 3 4 5 6 7 8 9 10
| jupyter notebook --generate-config
vim .jupyter/jupyter_notebook_config.py
c.NotebookApp.base_project_url = '/jupyter' c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.base_url = '/jupyter' c.NotebookApp.ip = '0.0.0.0'
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| cat /etc/nginx/nginx.conf
server { listen 80; server_name www.googj.com; location /jupyter { proxy_pass http://127.0.0.1:8888; proxy_set_header Host $host; 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; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 120s; proxy_next_upstream error; } }
|
重启服务器后,在网页上访问地址:http://www.googj.com/jupyter (这里是样例地址),就可以打开 Jupyterlab.
注意,上面假设已经配置了 Jupyterlab 自启,如果没有可以访问我的其他博文配置。并假设域名已经指向服务器IP地址。
参考链接
Jupyter Notebook在nginx中无法配置为二级页面的解决办法
nginx反向代理jupyterlab配置