Files
crewai/nginx.conf

130 lines
3.7 KiB
Nginx Configuration File
Raw Normal View History

2026-03-13 14:20:58 +08:00
events {
worker_connections 1024;
}
http {
# 上游服务器配置
upstream multi_agent_backend {
server multi-agent-system:8000;
keepalive 32;
}
# 日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
# 连接超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# SSE 特殊配置:禁用缓冲
# 这对于 Server-Sent Events 至关重要
map $http_accept $sse_connection {
default "keep-alive";
"text/event-stream" "keep-alive";
}
server {
listen 80;
server_name localhost;
# 客户端请求体大小限制
client_max_body_size 10M;
# API 代理配置
location /api/ {
proxy_pass http://multi_agent_backend;
# 必要的代理头
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;
# HTTP/1.1 支持SSE 必需)
proxy_http_version 1.1;
proxy_set_header Connection "";
# 禁用缓冲SSE 关键配置)
proxy_buffering off;
proxy_cache off;
proxy_request_buffering off;
# Chunked 传输编码
chunked_transfer_encoding on;
}
# SSE 流端点特殊配置
location /api/stream/ {
proxy_pass http://multi_agent_backend;
# 代理头
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# HTTP/1.1 和 Connection
proxy_http_version 1.1;
proxy_set_header Connection "";
# SSE 关键:完全禁用缓冲
proxy_buffering off;
proxy_cache off;
proxy_request_buffering off;
# Nginx 特殊指令:禁用 FastCGI 缓冲
fastcgi_buffering off;
# 保持长连接
proxy_connect_timeout 60s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
# SSE 心跳
proxy_ignore_client_abort off;
}
# 测试 UI 页面
location /test-ui {
proxy_pass http://multi_agent_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# 健康检查端点
location /health {
proxy_pass http://multi_agent_backend;
access_log off;
}
# API 文档
location /docs {
proxy_pass http://multi_agent_backend;
proxy_set_header Host $host;
}
location /openapi.json {
proxy_pass http://multi_agent_backend;
proxy_set_header Host $host;
}
}
# HTTPS 配置(可选,取消注释启用)
# server {
# listen 443 ssl http2;
# server_name your-domain.com;
#
# ssl_certificate /etc/nginx/ssl/fullchain.pem;
# ssl_certificate_key /etc/nginx/ssl/privkey.pem;
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_ciphers HIGH:!aNULL:!MD5;
#
# # 同样的代理配置...
# }
}