JupyterLab 服务器安装使用Nginx做代理

1
pip install jupyterlab

生成配置文件

1
jupyter lab --generate-config

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
# 工作目录
c.NotebookApp.notebook_dir = '/opt/jupyterhub'
# 不打开浏览器
c.NotebookApp.open_browser = False
# 允许所有IP访问
c.ServerApp.allow_origin = '*'
c.ServerApp.allow_remote_access = True
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.local_hostnames = ['*']
# 设置Token
c.ServerApp.token = ''

Nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
server {
listen 80;
listen 443 ssl http2;
server_name jupyter.ifan.host;
ssl_certificate /opt/openresty/nginx/cert/ifan/fullchain.cer;
ssl_certificate_key /opt/openresty/nginx/cert/ifan/ifan.host.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
access_log /var/log/openresty/nginx/logs/jupyter.access.log;
error_log /var/log/openresty/nginx/logs/jupyter.error.log;
location / {
proxy_http_version 1.1;
proxy_set_header Accept-Encoding gzip;
# WebSocket support
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

proxy_read_timeout 120s;
proxy_next_upstream error;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_buffering off;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 3s;
proxy_pass http://localhost:8888;
}
}

设置多环境

1
2
3
jupyter kernelspec list # 查看所有的jupyter核
pip install ipykernel
python -m ipykernel install --name ifan-env

设置中文

1
pip install jupyterlab-language-pack-zh-CN==3.3.post2