利用 nginx 反向代理為 jupyterlab 配置二級網址頁面


當服務器配置好 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
# 生成 jupyterlab 配置文件
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
# 配置 nginx
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地址。

參考鏈接

  1. Jupyter Notebook在nginx中無法配置為二級頁面的解決辦法

  2. nginx反向代理jupyterlab配置


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM