一个伪linux粉丝的blog

  1. 首页
  2. network
  3. 正文

Jupyter Notebook Nginx WebSocket

3 11 月, 2024 371点热度 0人点赞 0条评论

前言: 继上次帮客户搞GPU训练环境后,在后续使用Jupyter Notebook和 vscode (code-server) 时遇到了 2 个和 websocket 相关的小问题,这里记录一下。

问题1

反馈无法进入 notebook的 终端terminal.  出现空白页面,正常情况下是有一个终端显示的。

看了下浏览器调试模式下的报错,特征比较明显

websocket connection to 'wss://**' failed.
terminal websocket closed: undefined.
差异是之前走ip访问时功能正常,后来上了负载均衡后无法进入终端了,打听了一下,负载均衡是用的大家常见的nginx,那问题好解决了。

解决办法:

本地起一个nginx 复现并解决即可,测试发现下面的配置能解决这个问题。
关键配置如下:
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
http {
......
    upstream backend {
        server 10.29.14.37:30963;
    }
   map $http_upgrade $connection_upgrade {
      default upgrade;
      ''      close;
   }
 
    server {
        listen       80;
        listen       [::]:80;
        server_name  fakename.io;
 
        location / {
            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    }
# 443 ssl 部分也照抄即可
上面的作用就是让nginx支持 websocket
  • http里面的map的作用是:
    • 让转发到代理服务器的 "Connection"
    • 对于NGINX将升级请求从客户端发送到后台服务器,必须明确设置Upgrade和Connection标题。
      HTTP的Upgrade协议头机制用于将连接从HTTP连接升级到WebSocket连接,Upgrade机制使用了Upgrade协议头和Connection协议头。
参考资料
Nginx WebSocket
nginx反向代理时保持长连接

问题2

没过几天,下一个websocket 报错又来了,当使用vscode (code-server)时,报错

Error: WebSocket close with status code 1006

解决办法:

搜了一下,有现成的issue 讨论
https://github.com/coder/code-server/issues/6644
https://github.com/coder/code-server/issues/4443
 location 这里再加2行,最后1行顺带解决code server里面 上传 文件大小限制问题。
ws1006
1
2
3
            proxy_set_header   Host             $host;
            proxy_redirect     off;
            client_max_body_size 0;

相关文章:

  1. 基于Ubuntu Nginx Mongrel Mysql部署rails
  2. SSHTunnel Provides a Secure Internet Connection for Your Android
  3. Amazon EC2
  4. Azure cni No available addresses
标签: code-server Jupyter Notebook Nginx WebSocket
最后更新:3 11 月, 2024

wanjie

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

This site uses Akismet to reduce spam. Learn how your comment data is processed.

归档
分类
  • network / 332篇
  • Uncategorized / 116篇
  • unix/linux / 121篇
  • 业界资讯 / 38篇
  • 公司杂事 / 11篇
  • 数码影像 / 12篇
  • 美剧 / 3篇
  • 美图共赏 / 21篇
  • 英语学习 / 3篇
标签聚合
ldap 浏览器 ssh wget 泰国 nexus docker google-chrome Google 邮件归档 d90 dreamhost空间 k8s postgres 天翼live 网站运营 openssl Nginx 虚拟主机 deepseek dreamhost kernel squid debian gitlab VPS kubectl jira Ubuntu Google Voice

COPYRIGHT © 2008-2025 wanjie.info. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang