前置条件
操作步骤
Cloudflare配置子域名
DNS->Add record增加一条新纪录
Type | Name | Content |
---|---|---|
CNAME | 子域名 | 主域名 |
通过ping 子域名.主域名
检查是否配置成功(修改Cloudflare后需要等一段时间才能生效)
Docker compose安装部署jupyter lab
- 新建jupyter目录,此处以
/home/ubuntu/jupyter
为例
mkdir jupyter
cd jupyter
- 在目录中新建.jupyter文件,并修改读写权限
mkdir .jupyter
chmod -R 777 .jupyter
- 新建
docker-compose.yaml
文件
version: '3.1'
services:
jellyfin:
image: jupyter/scipy-notebook:latest
restart: "unless-stopped"
container_name: jupyter
ports:
- 8888:8888 #映射宿主机端口:容器端口
environment:
- "JUPYTER_ENABLE_LAB=yes"
- "RESTARTABLE=yes"
command: ["start-notebook.sh", "--NotebookApp.allow_origin='*'"]
volumes:
- /home/ubuntu/jupyter:/home/jovyan/work #映射宿主机工作目录:容器工作目录
- /home/ubuntu/jupyter/.jupyter:/home/jovyan/.jupyter #映射宿主机根目录:容器根目录
- /usr/local/nginx/etc/cert:/etc/nginx/cert #映射宿主机认证文件目录:容器认证文件目录
- 修改jupyter默认配置,打开
/home/ubuntu/jupyter/.jupyter/jupyter_server_config.py
修改如下内容:
c.ServerApp.allow_origin = '*'
c.ServerApp.allow_remote_access = True
c.ServerApp.certfile = '/etc/nginx/cert/cert.pem' #容器中SSL认证文件路径
c.ServerApp.keyfile = '/etc/nginx/cert/key.pem' #容器中SSL密钥文件路径
- 安装部署
docker compose up -d
使用docker ps
检查STATUS
是否为healthy
安装部署Nginx
- Docker compose安装
- 修改nginx配置:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream jupyter {
server 宿主机IP:宿主机端口;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name 二级域名;
ssl_certificate /etc/nginx/cert/cert.pem; # nginx容器中SSL认证文件路径
ssl_certificate_key /etc/nginx/cert/key.pem; # nginx容器中SSL密钥文件路径
ssl_client_certificate /etc/nginx/cert/cloudflare.crt; # nginx容器中Cloudflare源认证拉取文件路径
location / {
proxy_pass https://jupyter;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
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;
}
}
- 安装部署
docker compose up -d