feat: 调整端口映射,后端8182供Java渠道侧调用 [AC-AISVC-01]

- 后端端口从8080改为8182(宿主机映射)
- 前端端口8181保持不变
- 更新宿主机Nginx配置示例,支持前后端分离代理
- 容器间通信使用内部网络,无需修改
This commit is contained in:
MerCry 2026-02-26 01:46:24 +08:00
parent b6218dec1a
commit 7c8e4b6dc7
3 changed files with 75 additions and 7 deletions

View File

@ -100,12 +100,14 @@ docker compose logs -f ai-service
| 服务 | 地址 | 说明 | | 服务 | 地址 | 说明 |
|------|------|------| |------|------|------|
| 前端管理界面 | http://服务器IP:8181 | Vue 管理后台 | | 前端管理界面 | http://服务器IP:8181 | Vue 管理后台 |
| 后端 API | http://服务器IP:8080 | FastAPI 服务 | | 后端 API | http://服务器IP:8182 | FastAPI 服务Java渠道侧调用 |
| API 文档 | http://服务器IP:8080/docs | Swagger UI | | API 文档 | http://服务器IP:8182/docs | Swagger UI |
| Qdrant 控制台 | http://服务器IP:6333/dashboard | 向量数据库管理 | | Qdrant 控制台 | http://服务器IP:6333/dashboard | 向量数据库管理 |
| Ollama API | http://服务器IP:11434 | 嵌入模型服务 | | Ollama API | http://服务器IP:11434 | 嵌入模型服务 |
> **注意**: 如果宿主机 8080 端口已被占用,可以只通过前端管理界面 (8181) 访问,前端会自动代理后端 API 请求。 > **端口说明**:
> - `8181`: 前端管理界面,内部代理后端 API
> - `8182`: 后端 API供 Java 渠道侧直接调用
## 服务架构 ## 服务架构

View File

@ -2,17 +2,24 @@
# 将此文件放置于 /etc/nginx/conf.d/ai-service.conf # 将此文件放置于 /etc/nginx/conf.d/ai-service.conf
# 或 include 到主配置文件中 # 或 include 到主配置文件中
# 后端 API 上游(供 Java 渠道侧调用)
upstream ai_service_backend {
server 127.0.0.1:8182;
}
# 前端管理界面上游
upstream ai_service_admin { upstream ai_service_admin {
server 127.0.0.1:8181; server 127.0.0.1:8181;
} }
# 前端管理界面
server { server {
listen 80; listen 80;
server_name your-domain.com; # 替换为你的域名或服务器IP server_name your-domain.com; # 替换为你的域名或服务器IP
# 访问日志 # 访问日志
access_log /var/log/nginx/ai-service.access.log; access_log /var/log/nginx/ai-service-admin.access.log;
error_log /var/log/nginx/ai-service.error.log; error_log /var/log/nginx/ai-service-admin.error.log;
location / { location / {
proxy_pass http://ai_service_admin; 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) # HTTPS 配置示例 (使用 Let's Encrypt)
# ============================================================
# server { # server {
# listen 443 ssl http2; # listen 443 ssl http2;
# server_name your-domain.com; # 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 # HTTP 重定向到 HTTPS
# server { # server {
# listen 80; # listen 80;
# server_name your-domain.com; # server_name your-domain.com api.your-domain.com;
# return 301 https://$server_name$request_uri; # return 301 https://$server_name$request_uri;
# } # }

View File

@ -8,7 +8,7 @@ services:
container_name: ai-service container_name: ai-service
restart: unless-stopped restart: unless-stopped
ports: ports:
- "8080:8080" - "8182:8080"
environment: environment:
- AI_SERVICE_DEBUG=false - AI_SERVICE_DEBUG=false
- AI_SERVICE_LOG_LEVEL=INFO - AI_SERVICE_LOG_LEVEL=INFO