diff --git a/README.md b/README.md index 1f2571d..73f9574 100644 --- a/README.md +++ b/README.md @@ -100,12 +100,14 @@ docker compose logs -f ai-service | 服务 | 地址 | 说明 | |------|------|------| | 前端管理界面 | http://服务器IP:8181 | Vue 管理后台 | -| 后端 API | http://服务器IP:8080 | FastAPI 服务 | -| API 文档 | http://服务器IP:8080/docs | Swagger UI | +| 后端 API | http://服务器IP:8182 | FastAPI 服务(Java渠道侧调用) | +| API 文档 | http://服务器IP:8182/docs | Swagger UI | | Qdrant 控制台 | http://服务器IP:6333/dashboard | 向量数据库管理 | | Ollama API | http://服务器IP:11434 | 嵌入模型服务 | -> **注意**: 如果宿主机 8080 端口已被占用,可以只通过前端管理界面 (8181) 访问,前端会自动代理后端 API 请求。 +> **端口说明**: +> - `8181`: 前端管理界面,内部代理后端 API +> - `8182`: 后端 API,供 Java 渠道侧直接调用 ## 服务架构 diff --git a/deploy/nginx.conf.example b/deploy/nginx.conf.example index c4fda2f..c67246e 100644 --- a/deploy/nginx.conf.example +++ b/deploy/nginx.conf.example @@ -2,17 +2,24 @@ # 将此文件放置于 /etc/nginx/conf.d/ai-service.conf # 或 include 到主配置文件中 +# 后端 API 上游(供 Java 渠道侧调用) +upstream ai_service_backend { + server 127.0.0.1:8182; +} + +# 前端管理界面上游 upstream ai_service_admin { server 127.0.0.1:8181; } +# 前端管理界面 server { listen 80; server_name your-domain.com; # 替换为你的域名或服务器IP # 访问日志 - access_log /var/log/nginx/ai-service.access.log; - error_log /var/log/nginx/ai-service.error.log; + access_log /var/log/nginx/ai-service-admin.access.log; + error_log /var/log/nginx/ai-service-admin.error.log; location / { proxy_pass http://ai_service_admin; @@ -32,7 +39,39 @@ server { } } +# 后端 API(供 Java 渠道侧调用) +# 如果使用域名,可以用不同的路径或子域名 +# 示例:api.your-domain.com 或 your-domain.com/api/ +server { + listen 80; + server_name api.your-domain.com; # 替换为 API 子域名 + + # 访问日志 + access_log /var/log/nginx/ai-service-api.access.log; + error_log /var/log/nginx/ai-service-api.error.log; + + location / { + proxy_pass http://ai_service_backend; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_cache_bypass $http_upgrade; + + # SSE 流式响应支持 + proxy_read_timeout 300s; + proxy_connect_timeout 75s; + proxy_buffering off; + } +} + +# ============================================================ # HTTPS 配置示例 (使用 Let's Encrypt) +# ============================================================ + # server { # listen 443 ssl http2; # server_name your-domain.com; @@ -60,9 +99,36 @@ server { # } # } +# server { +# listen 443 ssl http2; +# server_name api.your-domain.com; +# +# ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; +# ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; +# +# ssl_protocols TLSv1.2 TLSv1.3; +# ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256; +# ssl_prefer_server_ciphers off; +# +# location / { +# proxy_pass http://ai_service_backend; +# proxy_http_version 1.1; +# proxy_set_header Upgrade $http_upgrade; +# proxy_set_header Connection 'upgrade'; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# proxy_cache_bypass $http_upgrade; +# proxy_read_timeout 300s; +# proxy_connect_timeout 75s; +# proxy_buffering off; +# } +# } + # HTTP 重定向到 HTTPS # server { # listen 80; -# server_name your-domain.com; +# server_name your-domain.com api.your-domain.com; # return 301 https://$server_name$request_uri; # } diff --git a/docker-compose.yaml b/docker-compose.yaml index eb6522b..eb0947b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,7 +8,7 @@ services: container_name: ai-service restart: unless-stopped ports: - - "8080:8080" + - "8182:8080" environment: - AI_SERVICE_DEBUG=false - AI_SERVICE_LOG_LEVEL=INFO