一、背景
有多台服务器都有部署jupyter notebook服务或者jupyter lab服务,可采用nginx进行配置,采用统一的入口,通过不同路由将请求分发到不同机器上
例如分别在10.10.10.10,10.10.10.11,10.10.10.12有部署jupyter服务,现在需要统一入口从10机器进入,通过nginx配置转发到11和12机器上
二、具体步骤
1、下载nginx容器,或从其他机器导出镜像文件scp后加载
docker pull nginx:latest docker save -o nginx.tar nginx:latest docker load -i nginx.tardocker pull nginx:latest docker save -o nginx.tar nginx:latest docker load -i nginx.tar
2、新建文件夹,构建ngxin配置文件
mkdir /data/nginx/
cd /data/nginx/
编辑配置文件:vim nginx.conf
1 user nginx; 2 events { 3 worker_connections 1000; 4 } 5 http { 6 map $http_upgrade $connection_upgrade { 7 default upgrade; 8 '' close; 9 } 10 11 client_max_body_size 0; 12 13 server { 14 listen 8100; 15 16 client_max_body_size 0; 17 18 location / { 19 proxy_set_header X-Forwarded-Host $host; 20 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 21 proxy_set_header X-Real-IP $remote_addr; 22 proxy_ssl_verify off; 23 proxy_pass http://10.10.10.10:8100; 24 proxy_redirect default; 25 proxy_http_version 1.1; 26 proxy_set_header Upgrade $http_upgrade; 27 proxy_set_header Connection "upgrade"; 28 client_max_body_size 0; 29 } 30 31 location /ailab1/ { 32 proxy_set_header X-Forwarded-Host $host; 33 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 34 proxy_set_header X-Real-IP $remote_addr; 35 proxy_ssl_verify off; 36 proxy_pass https://10.10.10.11:8100; 37 proxy_redirect default; 38 proxy_http_version 1.1; 39 proxy_set_header Upgrade $http_upgrade; 40 proxy_set_header Connection "upgrade"; 41 client_max_body_size 0; 42 } 43 location /ailab2/ { 44 proxy_set_header X-Forwarded-Host $host; 45 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 46 proxy_set_header X-Real-IP $remote_addr; 47 proxy_ssl_verify off; 48 proxy_pass https://10.10.10.12:8100; 49 proxy_redirect default; 50 proxy_http_version 1.1; 51 proxy_set_header Upgrade $http_upgrade; 52 proxy_set_header Connection "upgrade"; 53 client_max_body_size 0; 54 } 55 56 } 57 58 }
3、启动容器与nginx服务:
docker run -itd -p 8100:8100 -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf nginx:latest /docker-entrypoint.sh nginx -g 'daemon off;'
4、重启11,12机器得到jupyter服务,需添加一个NotebookApp.base_url参数,分别设置为nginx配置的路由:
nohup /usr/local/anaconda/bin/jupyter-lab --no-browser --port 8200 --ip=* --NotebookApp.base_url=/ailab1/ --allow-root >/dev/null 2>&1 &
5、连接测试:
10机器jupyter服务访问:https://myjupyter.com/tree/
11机器jupyter服务访问:https://myjupyter.com/ailab1/tree/
12机器jupyter服务访问:https://myjupyter.com/ailab2/tree/
标签:set,jupyter,header,配置,nginx,upgrade,proxy From: https://www.cnblogs.com/jax-/p/17649257.html