我在工作中有一个服务器,我登录该服务器以使用 jupyter 笔记本进行数据科学项目。多年来,无论是连接到校园 wifi 还是通过 VPN 远程连接,它都一直正常工作。现在,经过一些网络升级后,我仍然可以通过校园 wifi 连接,但通过 VPN 连接时,WebSocket connection to 'ws://server.internal/notebook/api/kernels/af23e3bf-65a7-47d4-8ad0-1afce22997f6/channels?session_id=5d17ad5ef8374ba4bff8f10d0e1ba3e4' failed:
控制台中会出现错误,导致出现错误窗口,提示Connection failed A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration.
我使用以下方式启动笔记本进程jupyter notebook --no-browser --notebook-dir=/data2 --ip=0.0.0.0 --port=8889
并使用 nginx 连接到笔记本服务器,配置如下
server {
listen 80;
listen [::]:80;
root /var/www/server.internal/html;
index index.html index.htm index.nginx-debian.html;
server_name server.internal;
location / {
try_files $uri $uri/index.html;
}
location /notebook {
proxy_pass http://localhost:8889;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
client_max_body_size 100m;
error_log /var/log/nginx/server_err.log debug;
}
在我的 nginx 日志中,我会看到一些错误,例如
2021/06/08 14:22:17 [error] 2258#2258: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.22.124.52, server: server.internal, request: "GET /notebook/api/sessions?_=1623089993100 HTTP/1.1", upstream: "http://[::1]:8889/notebook/api/sessions?_=1623089993100", host: "server.internal", referrer: "http://server.internal/notebook/tree/helen_mixed_infection/notebooks"
我的 jupyter 日志中没有出现任何错误,所以我认为这是一个网络问题,但想知道是否有办法解决它。