server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # Gzip Compression gzip on; gzip_vary on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; gzip_disable "MSIE [1-6]\."; # 增加上传文件大小限制 client_max_body_size 500M; location / { try_files $uri $uri/ /index.html; } # 后端API代理 location /api/ { proxy_pass http://backend:8000; proxy_http_version 1.1; 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; # 增加API超时时间 proxy_read_timeout 300s; proxy_send_timeout 300s; } # MCP Streamable HTTP 代理 # 对外以 /mcp 作为标准入口,避免 MCP Client 处理尾斜杠重定向。 location = /mcp { proxy_pass http://backend:8000; proxy_http_version 1.1; 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_set_header Connection ""; proxy_buffering off; proxy_request_buffering off; proxy_read_timeout 3600s; proxy_send_timeout 3600s; chunked_transfer_encoding on; } location = /mcp/ { return 308 /mcp; } location = /docs { proxy_pass http://backend:8000/docs; proxy_http_version 1.1; 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 = /redoc { proxy_pass http://backend:8000/redoc; proxy_http_version 1.1; 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 = /openapi.json { proxy_pass http://backend:8000/openapi.json; proxy_http_version 1.1; 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 = /docs/oauth2-redirect { proxy_pass http://backend:8000/docs/oauth2-redirect; proxy_http_version 1.1; 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 ^~ /uploads/ { proxy_pass http://backend:8000; proxy_http_version 1.1; 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; # 静态资源缓存配置 expires 30d; add_header Cache-Control "public, no-transform"; } # Cache static assets location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires 30d; add_header Cache-Control "public, no-transform"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }