feat(deploy): Complete PostgreSQL migration and Docker image build
Summary: - PostgreSQL database migration to RDS completed (90MB SQL, 11 schemas) - Frontend Nginx Docker image built and pushed to ACR (v1.0, ~50MB) - Python microservice Docker image built and pushed to ACR (v1.0, 1.12GB) - Created 3 deployment documentation files Docker Configuration Files: - frontend-v2/Dockerfile: Multi-stage build with nginx:alpine - frontend-v2/.dockerignore: Optimize build context - frontend-v2/nginx.conf: SPA routing and API proxy - frontend-v2/docker-entrypoint.sh: Dynamic env injection - extraction_service/Dockerfile: Multi-stage build with Aliyun Debian mirror - extraction_service/.dockerignore: Optimize build context - extraction_service/requirements-prod.txt: Production dependencies (removed Nougat) Deployment Documentation: - docs/05-部署文档/00-部署进度总览.md: One-stop deployment status overview - docs/05-部署文档/07-前端Nginx-SAE部署操作手册.md: Frontend deployment guide - docs/05-部署文档/08-PostgreSQL数据库部署操作手册.md: Database deployment guide - docs/00-系统总体设计/00-系统当前状态与开发指南.md: Updated with deployment status Database Migration: - RDS instance: pgm-2zex1m2y3r23hdn5 (2C4G, PostgreSQL 15.0) - Database: ai_clinical_research - Schemas: 11 business schemas migrated successfully - Data: 3 users, 2 projects, 1204 literatures verified - Backup: rds_init_20251224_154529.sql (90MB) Docker Images: - Frontend: crpi-cd5ij4pjt65mweeo.cn-beijing.personal.cr.aliyuncs.com/ai-clinical/ai-clinical_frontend-nginx:v1.0 - Python: crpi-cd5ij4pjt65mweeo.cn-beijing.personal.cr.aliyuncs.com/ai-clinical/python-extraction:v1.0 Key Achievements: - Resolved Docker Hub network issues (using generic tags) - Fixed 30 TypeScript compilation errors - Removed Nougat OCR to reduce image size by 1.5GB - Used Aliyun Debian mirror to resolve apt-get network issues - Implemented multi-stage builds for optimization Next Steps: - Deploy Python microservice to SAE - Build Node.js backend Docker image - Deploy Node.js backend to SAE - Deploy frontend Nginx to SAE - End-to-end verification testing Status: Docker images ready, SAE deployment pending
This commit is contained in:
191
frontend-v2/nginx.conf
Normal file
191
frontend-v2/nginx.conf
Normal file
@@ -0,0 +1,191 @@
|
||||
# Nginx 配置文件 - AI临床研究平台前端服务
|
||||
# 用途:托管 React SPA + 反向代理后端 API
|
||||
|
||||
user nginx;
|
||||
worker_processes auto; # 自动根据 CPU 核心数调整
|
||||
|
||||
# ⚠️ 日志输出到 stderr(SAE 会自动收集)
|
||||
error_log /dev/stderr warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024; # 每个 worker 进程的最大连接数
|
||||
use epoll; # Linux 下使用 epoll(高性能)
|
||||
}
|
||||
|
||||
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"';
|
||||
|
||||
# ⚠️ 日志输出到 stdout(SAE 会自动收集,避免磁盘写满)
|
||||
access_log /dev/stdout main;
|
||||
|
||||
# 性能优化
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
|
||||
# Gzip 压缩(减少传输大小)
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
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/rss+xml font/truetype font/opentype
|
||||
application/vnd.ms-fontobject image/svg+xml;
|
||||
gzip_disable "msie6";
|
||||
|
||||
# 上游后端服务(Backend Service)
|
||||
upstream backend {
|
||||
# ⚠️ 重要:这里的地址在部署时需要替换为真实的后端内网地址
|
||||
# SAE 部署时,通过环境变量注入,详见 Dockerfile
|
||||
server ${BACKEND_SERVICE_HOST}:${BACKEND_SERVICE_PORT} fail_timeout=30s max_fails=3;
|
||||
|
||||
# 如果有多个后端实例(负载均衡)
|
||||
# server 172.17.x.x:3001 weight=1;
|
||||
# server 172.17.x.y:3001 weight=1;
|
||||
|
||||
keepalive 32; # 保持连接池
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _; # 接受所有域名
|
||||
|
||||
# 根目录(React 构建产物)
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# 字符集
|
||||
charset utf-8;
|
||||
|
||||
# ==================== 静态资源处理 ====================
|
||||
|
||||
# 主页面(index.html)- 不缓存
|
||||
location = / {
|
||||
try_files /index.html =404;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
}
|
||||
|
||||
# JS/CSS 文件 - 强缓存(文件名带 hash)
|
||||
location ~* \.(js|css)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# 图片/字体文件 - 强缓存
|
||||
location ~* \.(png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# ==================== API 反向代理 ====================
|
||||
|
||||
# 后端 API 代理(关键配置)
|
||||
location /api/ {
|
||||
# 代理到后端服务
|
||||
proxy_pass http://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;
|
||||
|
||||
# 超时配置(AI 对话、文件处理可能耗时较长)
|
||||
proxy_connect_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
proxy_read_timeout 300s;
|
||||
|
||||
# 缓冲配置
|
||||
proxy_buffering off; # 关闭缓冲(实时流式响应)
|
||||
proxy_request_buffering off; # 支持大文件上传
|
||||
|
||||
# WebSocket 支持(如果后续需要)
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# 错误处理
|
||||
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
|
||||
proxy_next_upstream_tries 2;
|
||||
}
|
||||
|
||||
# ==================== SPA 路由支持 ====================
|
||||
|
||||
# React Router 路由回退
|
||||
# 所有非文件请求都返回 index.html(SPA 的核心)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# 禁用缓存(用户刷新时总是获取最新页面)
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
|
||||
# ==================== 安全加固 ====================
|
||||
|
||||
# 隐藏 Nginx 版本号
|
||||
server_tokens off;
|
||||
|
||||
# 禁止访问隐藏文件
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# 禁止访问特定文件
|
||||
location ~* \.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)$ {
|
||||
deny all;
|
||||
}
|
||||
|
||||
# ==================== 健康检查 ====================
|
||||
|
||||
# SAE 健康检查端点
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
|
||||
# Nginx 状态页(用于监控)
|
||||
location /nginx_status {
|
||||
stub_status on;
|
||||
access_log off;
|
||||
# 仅允许内网访问
|
||||
allow 10.0.0.0/8;
|
||||
allow 172.17.0.0/16;
|
||||
allow 192.168.0.0/16;
|
||||
deny all;
|
||||
}
|
||||
|
||||
# ==================== 错误页面 ====================
|
||||
|
||||
error_page 404 /index.html; # SPA 路由回退
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user