关于某项目的部署改造方案
原创2024/5/6大约 2 分钟
关于某项目的部署改造方案
1、业务背景
现有 DLearn 产品和其他部门研发的图像标注产品(后称虎视模块),二者分别有独立的 Java 后端项目提供服务,虎视模块采用 docker-compose 部署,DLearn 采用 docker 部署,并同时部署了一个 nginx 代理。DLearn 产品上的部分页面和接口直接由虎视模块提供,通过 nginx 代理的形式集成到了 DLearn 平台上,其中不乏一些图片的访问,是利用 nginx 对服务器的指定目录进行的静态资源映射(虎视模块会将图片上传到服务器上)。
自 DLearn 4.0 版本起,DLearn 后端集成了 Spring Cloud 微服务架构,并接入了 Nacos(内称Secoc) 配置中心和 Apisix(内称Virgil) 网关。
2、需求目标
对于虎视接口的代理,要通过 virgil 代理访问而非 nginx,且图片也要在平台中正常展示(静态资源映射)。
3、需求分析
由于 virgil 不支持静态资源的代理,因此只能考虑保留 nginx 的部署。但 nginx 中只有相对固定的配置,因此可以考虑和虎视的模块部署放到一块,因为虎视模块是通过 docker-compose 启动的。
4、解决方案
(1)重新整理了一下安装包,把 nginx 的镜像文件放进去
(2)把 nginx 的配置文件放到固定目录(如:nginx)下,配置内容固定如下:
server {
listen 60003;
server_name localhost;
client_max_body_size 200m;
access_log /var/log/nginx/host.access.log;
error_log /var/log/nginx/host.error.log;
rewrite "^/tigervisionimg/(.*)$" /$1;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /workspaces {
root /home/ubuntu;
autoindex on;
autoindex_format html;
}
location /tigervisionapi {
proxy_ignore_client_abort on;
fastcgi_connect_timeout 120;
fastcgi_send_timeout 120;
fastcgi_read_timeout 120;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass http://127.0.0.1:60001/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
}
location /tigervisionmodelapi {
proxy_ignore_client_abort on;
fastcgi_connect_timeout 120;
fastcgi_send_timeout 120;
fastcgi_read_timeout 120;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass http://127.0.0.1:60002/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}(3)修改 docker-compose.yml 文件,新增以下模块(注意网络要改为 host 模式,否则它的代理访问不通虎视后端服务):
tigervision_image_access:
image: 62.234.217.203:52521/middleware/nginx:latest
hostname: tigervision_image_access
container_name: tigervision_image_access
network_mode: host
# networks:
# - wlnet
restart: always
# ports:
# - "60003:3608"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/certificate:/etc/nginx/certificate
- /home/cmes/static:/home/ubuntu
environment:
TZ: Asia/Shanghai
LANG: C.UTF-8
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "5"(4)在 virgil 上,添加对 tigervisionapi、tigervisionmodelapi(实际用不到) 的路由代理。

