0%

Jupyter 无法连接到 Python

问题描述

1
kernel connecting

及无法连接到后端的 Python, Shell 也无法打开

架构

笔者采用 jupyter docker + nginx 反向代理这个模式

打开日志发现

1
[W 2022-02-22 15:14:10.078 ServerApp] 400 GET /terminals/websocket/1 (172.18.0.1) 0.67ms referer=None

解决方法

更改 nginx 反向代理配置, 可能是没有识别websocket请求所致, 具体原因尚不清楚, 但以下这个配置在笔者这里可用

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
location ~* \.(gif|png|jpg|css|js|woff|woff2)$
{
proxy_pass https://127.0.0.1:10000;
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_set_header REMOTE-HOST $remote_addr;
expires 12h;
}
location /
{
proxy_pass https://127.0.0.1:10000;
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_set_header REMOTE-HOST $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";

add_header X-Cache $upstream_cache_status;

#Set Nginx Cache

add_header Cache-Control no-cache;
}