使用 frp 远程连接 Jupyter Lab/Notebook 无法连接到 Kernel, F12 查看控制台输出, 发现是有关 websocket failed 的错误. 一番搜索后发现是跳板机的问题.
frp server 跑在跳板机上, 使用 nginx 做的域名映射如下:
server {
listen 80;
server_name "xxx.xxxxx.xxxx";
location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Powered-By;
}
}
Jupyter Lab/Notebook 在建立 Kernel 连接时用的是 WebSocket, 上面的域名映射默认不支持, 需要添加额外的 WebSocket 相关的映射, 修改后如下:
server {
listen 80;
server_name "xxx.xxxxx.xxxx";
location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Powered-By;
}
location /api/kernels/ {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
location /terminals/ {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
}
即把 /api/kernels/
和/terminals/
的协议更新为 WebSocket 即可.