# 上游长连接池(性能整改 P0-2):与 v2-api 复用连接,消除每请求 TCP 建连; # keepalive 连接需配合 proxy_http_version 1.1 + proxy_set_header Connection "" upstream v2_api { server v2-api:3001; keepalive 64; } # 防洪峰兜底限流(app 层 120 req/min/IP 更严,这里只挡瞬时洪峰/扫描; # 默认 503 会误判服务故障,显式 429) limit_req_zone $binary_remote_addr zone=public_api:10m rate=50r/s; limit_req_status 429; server { listen 80; server_name official.inkreach.cc; client_max_body_size 10m; # ACME challenge for cert renewals location /.well-known/acme-challenge/ { root /var/www/certbot; } location / { return 301 https://$host$request_uri; } } server { listen 443 ssl; http2 on; server_name official.inkreach.cc; ssl_certificate /etc/nginx/certs/official.inkreach.cc_ecc/fullchain.cer; ssl_certificate_key /etc/nginx/certs/official.inkreach.cc_ecc/official.inkreach.cc.key; ssl_protocols TLSv1.2 TLSv1.3; client_max_body_size 10m; root /usr/share/nginx/html; # ACME challenge for cert renewals location /.well-known/acme-challenge/ { root /var/www/certbot; } # Admin SPA location /admin/ { try_files $uri $uri/ /admin/index.html; } location = /admin { return 301 /admin/; } # v2(refactor/v2 分支)路径分流:SPA 原样透传给 v2 admin 容器,/v2-api 去掉前缀转发到 v2 api location /v2/admin/ { proxy_pass http://v2-admin:80; 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; } # v2 版 H5:透传给 v2 admin 容器(文件在 v2 镜像内,路径 /v2/h5/) location /v2/h5/ { proxy_pass http://v2-admin:80; 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 /v2-api/ { proxy_pass http://v2_api/; proxy_http_version 1.1; proxy_set_header Connection ""; 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 5s; proxy_read_timeout 30s; proxy_send_timeout 30s; limit_req zone=public_api burst=200 nodelay; } # H5 历史构建的 API 基址是同源相对路径 /public/*(BASE_URL="/"),直通 v2 api(路径原样透传) location /public/ { proxy_pass http://v2_api; proxy_http_version 1.1; proxy_set_header Connection ""; 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 5s; proxy_read_timeout 30s; proxy_send_timeout 30s; limit_req zone=public_api burst=200 nodelay; } location = /h5 { return 301 /h5/; } location /h5/{ try_files $uri $uri/ /h5/index.html; } # Uploaded files served by the API. # 缓存头注意:若运营有「同名替换图片」操作请改短 max-age 或改用版本化 URL location /uploads/ { proxy_pass http://v2_api/uploads/; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; expires 30d; add_header Cache-Control "public"; } # Static product assets served by the API(哈希文件名,可长缓存) location /assets/ { proxy_pass http://v2_api/assets/; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; expires 30d; add_header Cache-Control "public"; } # Website placeholder until the public site is deployed location / { return 302 /v2/admin/; } }