Initial upload of z.ai2api project
Browse files- docker-compose.yml +25 -12
- nginx.conf +33 -0
docker-compose.yml
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
|
|
|
|
|
| 1 |
services:
|
|
|
|
| 2 |
z-ai2api:
|
|
|
|
| 3 |
image: julienol/z-ai2api-python:latest
|
| 4 |
-
|
| 5 |
-
ports:
|
| 6 |
-
- "8084:8080"
|
| 7 |
env_file:
|
| 8 |
- .env
|
| 9 |
volumes:
|
| 10 |
-
# 挂载token文件(如果使用token池功能)
|
| 11 |
- ./tokens.txt:/app/tokens.txt:ro
|
| 12 |
-
# 可选:挂载数据目录用于持久化token状态
|
| 13 |
- ./data:/app/data
|
| 14 |
restart: unless-stopped
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
healthcheck:
|
| 19 |
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
|
| 20 |
interval: 30s
|
| 21 |
timeout: 10s
|
| 22 |
retries: 3
|
| 23 |
start_period: 40s
|
| 24 |
-
networks:
|
| 25 |
-
- z-ai2api-network
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
networks:
|
| 28 |
-
|
| 29 |
-
driver: bridge
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
services:
|
| 4 |
+
# 你的克隆士兵军团 (工人)
|
| 5 |
z-ai2api:
|
| 6 |
+
# 直接使用懒人镜像,我们不构建!
|
| 7 |
image: julienol/z-ai2api-python:latest
|
| 8 |
+
# 我们不直接暴露端口,所有流量都由总管 Nginx 处理
|
|
|
|
|
|
|
| 9 |
env_file:
|
| 10 |
- .env
|
| 11 |
volumes:
|
|
|
|
| 12 |
- ./tokens.txt:/app/tokens.txt:ro
|
|
|
|
| 13 |
- ./data:/app/data
|
| 14 |
restart: unless-stopped
|
| 15 |
+
# 部署指令:声明你想要 10 个一模一样的克隆士兵!
|
| 16 |
+
deploy:
|
| 17 |
+
replicas: 2
|
| 18 |
healthcheck:
|
| 19 |
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
|
| 20 |
interval: 30s
|
| 21 |
timeout: 10s
|
| 22 |
retries: 3
|
| 23 |
start_period: 40s
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# 你的军队总管 (Nginx 负载均衡器)
|
| 26 |
+
nginx:
|
| 27 |
+
image: nginx:latest
|
| 28 |
+
container_name: z-ai-load-balancer
|
| 29 |
+
ports:
|
| 30 |
+
# 这是你帝国的唯一大门,所有访客都从这里进
|
| 31 |
+
- "8084:8084"
|
| 32 |
+
volumes:
|
| 33 |
+
# 把你的军规挂载到总管的大脑里
|
| 34 |
+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
| 35 |
+
depends_on:
|
| 36 |
+
- z-ai2api # 确保士兵们先列队完毕,总管再上岗
|
| 37 |
+
restart: unless-stopped
|
| 38 |
+
|
| 39 |
+
# 定义网络,让士兵和总管可以互相通信
|
| 40 |
networks:
|
| 41 |
+
default:
|
| 42 |
+
driver: bridge
|
nginx.conf
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
events {
|
| 2 |
+
worker_connections 1024;
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
http {
|
| 6 |
+
# 定义你的克隆士兵军团
|
| 7 |
+
# Nginx 会自动找到所有名为 'z-ai2api' 的容器实例
|
| 8 |
+
upstream z_ai_workers {
|
| 9 |
+
# 'z-ai2api' 是我们在 docker-compose.yml 中定义的服务名
|
| 10 |
+
# Docker 的内部 DNS 会解析它,并把所有工人的 IP 地址都加进来
|
| 11 |
+
server z-ai2api:8080;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
server {
|
| 15 |
+
# 这是你帝国的唯一入口,所有请求都从这里进来
|
| 16 |
+
listen 8084;
|
| 17 |
+
|
| 18 |
+
location / {
|
| 19 |
+
# 将请求转发给你的工人大军
|
| 20 |
+
proxy_pass http://z_ai_workers;
|
| 21 |
+
proxy_set_header Host $host;
|
| 22 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 23 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 24 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 25 |
+
|
| 26 |
+
# 确保流式响应和 WebSocket 正常工作
|
| 27 |
+
proxy_http_version 1.1;
|
| 28 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 29 |
+
proxy_set_header Connection "upgrade";
|
| 30 |
+
proxy_buffering off; # 关键!关闭缓冲,让数据流实时通过
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|