mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-14 13:06:51 +00:00
chore(deploy): 成品部署链路、依赖分组与运维基建
部署方式:服务器不再接收源码、不执行构建,改为本地构建成品后交付
- deploy-artifacts.sh:构建→备份→校验→原子替换,支持回滚、镜像/备份轮转、
mysql 与 postgres 双变体镜像;后端以 docker save|ssh|docker load 交付
- 依赖分组:requirements/{base,storage}.txt + db/{mysql,postgres,sqlite}.txt,
镜像按所选数据库只装对应驱动(MySQL 变体 565MB → 521MB)
编排与运行时加固
- compose:MySQL/Redis/backend 端口仅绑 127.0.0.1;密钥(SECRET_KEY、
DATA_ENCRYPTION_KEY、DATA_ENCRYPTION_OLD_KEYS)、PROD_CORS_ORIGINS、
FORWARDED_ALLOW_IPS、DEMO_ENABLE 一律由 docker/.env 注入
- Dockerfile:对齐依赖分组、以非 root(uid=1000) 运行;.dockerignore 排除全部真实 .env.*
- nginx:静态资源长缓存、隐藏文件拒绝、接口文档仅内网可访问、放行 ACME http-01 校验路径
工程基建
- 新增 CI:backend(uv sync + ruff + pytest)与 frontend(web type-check+vitest、app type-check)
- 新增 DEPLOYMENT.md 运维手册(部署/回滚/密钥轮换/每日巡检/证书/排查)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
# 静态资源长缓存 + 隐藏文件防护。被 nginx.conf 的 /web、/app location include。
|
||||
# 撤销:删除本文件 + 移除 nginx.conf 中对应 include 行,然后重建 nginx。
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
location ~* ^/(web|app|docs)/(js|css|assets|static)/ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
access_log off;
|
||||
}
|
||||
location ~* ^/(web|app|docs)/[^/]*\.(?:png|jpe?g|gif|svg|webp|ico|woff2?|ttf|eot)$ {
|
||||
add_header Cache-Control "public, max-age=2592000";
|
||||
access_log off;
|
||||
}
|
||||
+33
-2
@@ -69,11 +69,22 @@ http {
|
||||
limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
|
||||
|
||||
# ==================== HTTP -> HTTPS 重定向 ====================
|
||||
# HTTP server块 - 重定向到HTTPS
|
||||
# HTTP server块 - 重定向到HTTPS(放行 ACME 校验路径,供证书自动续期使用)
|
||||
server {
|
||||
listen 80;
|
||||
server_name service.fastapiadmin.com;
|
||||
return 301 https://$server_name$request_uri;
|
||||
|
||||
# 证书续期校验路径(ACME http-01):必须在 301 之前放行,
|
||||
# 否则签发/续期校验请求会被重定向到 https 而导致验证失败。
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /usr/share/nginx/html/acme;
|
||||
default_type "text/plain";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
# ==================== HTTPS Server ====================
|
||||
@@ -101,17 +112,37 @@ http {
|
||||
|
||||
# ==================== 前端(/web) ====================
|
||||
location /web {
|
||||
include cache-headers.inc; # 静态资源长缓存(优化项,可删除)
|
||||
alias /usr/share/nginx/html/web/dist;
|
||||
try_files $uri $uri/ /web/index.html; #解决页面刷新404问题
|
||||
}
|
||||
location ~ /\. { deny all; access_log off; log_not_found off; }
|
||||
|
||||
|
||||
# ==================== 小程序 H5(/app) ====================
|
||||
# 已禁用:app 不开源,如需使用请取消注释
|
||||
location /app {
|
||||
include cache-headers.inc; # 静态资源长缓存(优化项,可删除)
|
||||
alias /usr/share/nginx/html/app/dist/build/h5;
|
||||
try_files $uri $uri/ /app/index.html; #解决页面刷新404问题
|
||||
}
|
||||
location ~ /\. { deny all; access_log off; log_not_found off; }
|
||||
|
||||
|
||||
|
||||
# ==================== 封堵接口文档(仅本机/内网可访问)====================
|
||||
location ~ ^/api/v1/(docs|redoc|openapi\.json)$ {
|
||||
allow 127.0.0.1;
|
||||
allow 10.0.0.0/8;
|
||||
allow 172.16.0.0/12;
|
||||
allow 192.168.0.0/16;
|
||||
deny all;
|
||||
proxy_pass http://backend:8001;
|
||||
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 代理 ====================
|
||||
location /api/v1 {
|
||||
limit_req zone=api_limit burst=60 nodelay;
|
||||
|
||||
Reference in New Issue
Block a user