Jupyter服务搭建

By admin , 11 十月, 2025

安装软件:

$ sudo apt install -y python3 python3-pip python3-venv
$ useradd jupyter -m
$ su - jupyter
$ python3 -m venv jupyter-env
$ source jupyter-env/bin/activate
$ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
$ pip install jupyter

配置Jupyter:

$ jupyter notebook --generate-config
$ jupyter notebook password
$ vi ~/.jupyter/jupyter_notebook_config.py
c.ServerApp.allow_origin = 'https://yourhost/'
c.ServerApp.allow_remote_access = True
c.ServerApp.base_url = '/jupyter/'

启动服务:

$ nohup jupyter notebook --no-browser > jupyter.log 2>&1 &

 配置Nginx:

    # 核心反向代理配置
    location /jupyter/ {
        # 将请求转发给Jupyter
        proxy_pass http://127.0.0.1:8013;

        # 关键:传递原始主机名、IP和协议给后端
        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 X-Forwarded-Proto $scheme;

        # WebSocket支持 (Jupyter需要)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # 增加超时时间,防止长时间运行的单元格被断开
        proxy_read_timeout 86400;
    }

 

标签

评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
CAPTCHA
请输入"Drupal"
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

最新内容