Spaces:
Sleeping
Sleeping
| worker_processes auto; | |
| events { | |
| worker_connections 1024; | |
| use epoll; | |
| accept_mutex on; | |
| multi_accept on; | |
| } | |
| http { | |
| # 基础配置 | |
| include 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"'; | |
| access_log /var/log/nginx/access.log main; | |
| error_log /var/log/nginx/error.log warn; | |
| # 性能优化 | |
| sendfile on; | |
| tcp_nopush on; | |
| tcp_nodelay on; | |
| keepalive_timeout 65; | |
| types_hash_max_size 2048; | |
| client_max_body_size 100M; | |
| # Gzip 压缩 | |
| gzip on; | |
| gzip_vary on; | |
| gzip_min_length 1024; | |
| gzip_types text/plain text/css text/xml text/javascript | |
| application/json application/javascript application/xml+rss | |
| application/atom+xml image/svg+xml; | |
| upstream appfast { | |
| server localhost:8000; | |
| keepalive 32; | |
| } | |
| upstream appflask { | |
| server localhost:5000; | |
| keepalive 32; | |
| } | |
| upstream supervisor { | |
| server localhost:9001; | |
| keepalive 32; | |
| } | |
| upstream appdjango { | |
| server localhost:8001; | |
| keepalive 32; | |
| } | |
| server { | |
| listen 7860; | |
| server_name localhost; | |
| location /root { | |
| alias "/app"; | |
| charset utf-8; | |
| autoindex on; | |
| } | |
| # 健康检查端点 | |
| location /health { | |
| access_log off; | |
| add_header Content-Type application/json; | |
| return 200 '{"status": "healthy", "timestamp": "$time_iso8601", "services": ["nginx", "fastapi", "flask"]}'; | |
| } | |
| # 服务状态端点 | |
| location /status { | |
| proxy_pass http://supervisor; | |
| 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; | |
| allow 127.0.0.1; | |
| deny all; | |
| } | |
| location /status2 { | |
| # nginx status | |
| stub_status on; | |
| access_log off; | |
| } | |
| # 静态文件 | |
| location /static/ { | |
| alias /app/static/; | |
| expires 30d; | |
| add_header Cache-Control "public, immutable"; | |
| } | |
| # API 路由 | |
| location /appfast/ { | |
| proxy_pass http://appfast/; | |
| 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 60s; | |
| proxy_send_timeout 60s; | |
| proxy_read_timeout 60s; | |
| } | |
| location /appflask/ { | |
| proxy_pass http://appflask/; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| } | |
| location /supervisor/ { | |
| proxy_pass http://supervisor/; | |
| proxy_set_header Host $host:$proxy_port; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header X-Forwarded-Host $http_host; | |
| proxy_set_header X-Forwarded-Port $server_port; | |
| proxy_set_header X-Forwarded-Proto $scheme; | |
| } | |
| # appdjango 媒体文件 | |
| location /media/ { | |
| alias /app/app_django/media/; | |
| expires 30d; | |
| } | |
| # API 路由 | |
| location /api/ { | |
| proxy_pass http://appdjango; | |
| 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 60s; | |
| proxy_send_timeout 60s; | |
| proxy_read_timeout 60s; | |
| } | |
| # 管理后台 | |
| location /admin/ { | |
| proxy_pass http://appdjango; | |
| 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 / { | |
| # proxy_pass http://appdjango; | |
| # 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; | |
| #} | |
| } | |
| } |