1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
## 媒体处理基建部署 (imgproxy + Nginx CDN 缓存)
##
## 作用:
## 提供支持动态转换(裁剪、缩放、打水印等)的高性能图片服务。
## 由 Nginx 提供第一层 CDN 热点缓存,防止打穿底层计算实例及 MinIO。
##
## 在 docker 目录下执行:
## docker compose -f docker-compose-imgproxy.yml up -d
##
## 停止:
## docker compose -f docker-compose-imgproxy.yml down
services:
# 图片处理网关
imgproxy:
image: darthsim/imgproxy:v3.27.0
container_name: fbc-imgproxy
environment:
- IMGPROXY_LOG_LEVEL=info
# 注意:配置成允许访问内网 IP(如果在同一个机器)以便访问 MinIO
- IMGPROXY_ALLOW_ORIGIN=localhost
# 是否开启原图直接返回(当格式/尺寸没变时)
- IMGPROXY_ENFORCE_WEBP=true
- IMGPROXY_AUTO_WEBP=true
# 防止 SSRF, 但我们要它能访问本地或公网 Minio,可调节限制范围
- IMGPROXY_ALLOWED_SOURCES=*
# ---- 增加以连上当前的 rustfs S3 兼容存储 ----
- IMGPROXY_USE_S3=true
- IMGPROXY_S3_ENDPOINT=http://fbc-rustfs:9000
- AWS_ACCESS_KEY_ID=${RUSTFS_ROOT_USER:-rustfsadmin}
- AWS_SECRET_ACCESS_KEY=${RUSTFS_ROOT_PASSWORD:-rustfsadmin}
- AWS_S3_FORCE_PATH_STYLE=true
# 配置安全密钥防止外部盗用其计算资源,开启 URL 签名验证
# 后续在后端 (如 ms-oss) 生成外链时,需要使用相同的 Key 和 Salt 进行签名
- IMGPROXY_KEY=7a8f3b14e9c60d852a41f69c7b3e10d8f5c246b9a81f3d7e5b4c90a2c58efb13
- IMGPROXY_SALT=3b9d6c2a8f4e15079a408bec1b305d2e7f849c31b26a5cd9e10fa78c6b4e3902
ports:
- "8084:8080" # 直接访问端口,调试用
healthcheck:
test:
interval: 10s
timeout: 3s
retries: 3
restart: unless-stopped
# Nginx 缓存层(本地轻级 CDN)
nginx-cdn:
image: nginx:alpine
container_name: fbc-nginx-cdn
ports:
- "8085:80" # 最终暴漏出的带缓存的业务访问端口
volumes:
- ./nginx-cdn/imgproxy_cache.conf:/etc/nginx/conf.d/default.conf:ro
- nginx_cache_data:/var/cache/nginx
depends_on:
- imgproxy
restart: unless-stopped
volumes:
nginx_cache_data: