前情提要:花了大半天成功部署上jupyter,结果发现不能执行代码单元,继续折腾..
问题描述
- 前端jupyer lab界面执行代码单元无响应,且提示
Kernel status:Disconnected
- 后台jupyter容器日志提示400报错
docker logs -f 容器id
400 GET /api/kernels/9506be3c-2544-4ab9-b9af-b2a1c51a1402/...
解决方法
- 修改nginx配置,在配置中增加如下内容:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
auth_basic "Restricted Content";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Origin "";
proxy_read_timeout 86400;
完整配置文件为
upstream my-notebook-workhorse {
server 127.0.0.1:8888 fail_timeout=0;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# let my-notebook deal with the redirection
server {
listen 80;
server_name my-notebook.wh;
server_tokens off;
root /dev/null;
# Increase this if you want to upload larger attachments
client_max_body_size 20m;
# individual nginx logs for this vhost
access_log /var/log/nginx/my-notebook_access.log;
error_log /var/log/nginx/my-notebook_error.log;
location / {
proxy_pass http://my-notebook-workhorse;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
auth_basic "Restricted Content";
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Origin "";
proxy_read_timeout 86400;
}
}
- 重新启动nginx后再次执行代码单元格运行正常
docker-compose restart nginx
Reference
https://stackoverflow.com/questions/42350182/jupyter-notebook-keeps-reconnecting-to-kernel