forked from xiaohei/taiji-AI-PAD
- 修复MCP Server数据库连接和导入问题 - 创建Data Ingestion服务核心模块 - 配置阿里云镜像源提升构建速度 - 添加项目状态报告和文档 - 完善微服务架构基础设施
255 lines
7.6 KiB
Nginx Configuration File
255 lines
7.6 KiB
Nginx Configuration File
user nginx;
|
|
worker_processes auto;
|
|
error_log /var/log/nginx/error.log notice;
|
|
pid /var/run/nginx.pid;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
use epoll;
|
|
multi_accept on;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
# 日志格式
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
'"$http_user_agent" "$http_x_forwarded_for" '
|
|
'rt=$request_time ut="$upstream_response_time"';
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
# 基础配置
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
client_max_body_size 50M;
|
|
|
|
# Gzip压缩
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/xml
|
|
text/javascript
|
|
application/json
|
|
application/javascript
|
|
application/xml+rss
|
|
application/atom+xml
|
|
image/svg+xml;
|
|
|
|
# 上游服务器配置
|
|
upstream mcp-server {
|
|
least_conn;
|
|
server mcp-server:8000 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
upstream data-ingestion {
|
|
least_conn;
|
|
server data-ingestion:8000 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
upstream litellm-gateway {
|
|
least_conn;
|
|
server litellm-gateway:4000 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
# 限流配置
|
|
limit_req_zone $binary_remote_addr zone=api:10m rate=100r/m;
|
|
limit_req_zone $binary_remote_addr zone=auth:10m rate=20r/m;
|
|
|
|
# 主服务器配置
|
|
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# 安全头
|
|
add_header X-Frame-Options DENY;
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin";
|
|
|
|
# 健康检查端点
|
|
location /health {
|
|
access_log off;
|
|
return 200 "OK\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# MCP服务器路由
|
|
location /api/mcp/ {
|
|
limit_req zone=api burst=50 nodelay;
|
|
|
|
proxy_pass http://mcp-server/;
|
|
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;
|
|
|
|
# WebSocket支持
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
# 超时设置
|
|
proxy_connect_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
proxy_read_timeout 30s;
|
|
|
|
# 缓冲设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
}
|
|
|
|
# 数据接入服务路由
|
|
location /api/data/ {
|
|
limit_req zone=api burst=30 nodelay;
|
|
|
|
proxy_pass http://data-ingestion/;
|
|
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_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 300s;
|
|
}
|
|
|
|
# Agent注册中心路由 (暂时返回服务不可用)
|
|
location /api/agents/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
|
|
# 临时返回服务不可用
|
|
return 503 '{"error": "Service Unavailable", "message": "Agent Registry service is temporarily disabled", "status": "maintenance"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
|
|
# 计费引擎路由
|
|
location /api/billing/ {
|
|
limit_req zone=api burst=100 nodelay;
|
|
|
|
proxy_pass http://billing-engine/;
|
|
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_connect_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
proxy_read_timeout 30s;
|
|
}
|
|
|
|
# LiteLLM网关路由
|
|
location /api/llm/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
|
|
proxy_pass http://litellm-gateway/;
|
|
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;
|
|
|
|
# LLM请求可能需要更长时间
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 300s;
|
|
}
|
|
|
|
# 静态文件
|
|
location /static/ {
|
|
alias /usr/share/nginx/html/static/;
|
|
expires 1d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# API文档路由
|
|
location /docs {
|
|
proxy_pass http://mcp-server/docs;
|
|
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;
|
|
}
|
|
|
|
# 默认路由
|
|
location / {
|
|
return 404 '{"error": "Not Found", "message": "请使用正确的API端点"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
|
|
# 错误页面
|
|
error_page 404 /404.html;
|
|
error_page 500 502 503 504 /50x.html;
|
|
|
|
location = /404.html {
|
|
return 404 '{"error": "Not Found", "message": "请求的资源不存在"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
|
|
location = /50x.html {
|
|
return 500 '{"error": "Internal Server Error", "message": "服务器内部错误"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
}
|
|
|
|
# HTTPS配置(生产环境使用)
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name localhost;
|
|
|
|
# SSL证书配置(需要实际证书文件)
|
|
# ssl_certificate /etc/nginx/ssl/cert.pem;
|
|
# ssl_certificate_key /etc/nginx/ssl/key.pem;
|
|
|
|
# SSL配置
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
|
|
# HSTS
|
|
add_header Strict-Transport-Security "max-age=63072000" always;
|
|
|
|
# 其他配置与HTTP相同...
|
|
|
|
# 临时重定向到HTTP(开发环境)
|
|
return 301 http://$server_name$request_uri;
|
|
}
|
|
|
|
# 监控和状态页面
|
|
server {
|
|
listen 8080;
|
|
server_name localhost;
|
|
|
|
location /nginx_status {
|
|
stub_status on;
|
|
access_log off;
|
|
allow 127.0.0.1;
|
|
allow 172.20.0.0/16; # Docker网络
|
|
deny all;
|
|
}
|
|
|
|
location /health {
|
|
access_log off;
|
|
return 200 "Nginx OK\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
}
|
|
}
|
|
|