docs(README): 更新项目文档并添加部署指南

- 在 README.md 中添加了详细的项目结构、快速开始、使用指南、开发指南等内容
- 新增生产环境部署步骤,包括前端和后端的构建
This commit is contained in:
2025-08-06 16:06:35 +08:00
parent 67f189995e
commit 8cdba1c0e6
5 changed files with 261 additions and 13 deletions

10
docker/caddy/Caddyfile Normal file
View File

@@ -0,0 +1,10 @@
主配置文件,在/config目录
{
# 全局选项:可关掉自动 HTTPS测试环境
# auto_https off
}
# 自动引入子配置
import sites-enabled/*.caddy

View File

@@ -0,0 +1,56 @@
反向代理,后端的反向代理,在/config/caddy.d目录下
xxx.com { # 你的域名
# 处理预检请求
@options method OPTIONS
handle @options {
header Access-Control-Allow-Origin "*"
header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS"
header Access-Control-Allow-Headers "Content-Type, Authorization"
header Access-Control-Allow-Credentials "true"
header Access-Control-Max-Age "3600"
respond "" 204
}
# 为实际请求添加CORS头部
header {
Access-Control-Allow-Origin "*"
Access-Control-Allow-Credentials "true"
}
# 反向代理到Gitea服务器的IP和端口
reverse_proxy http://ip:8084 { #若是后端与caddy在同一个网络可以直接指定后端的容器名
# 移除后端返回的 CORS 头(防止冲突)
header_down -Access-Control-Allow-Origin
header_down -Access-Control-Allow-Methods
header_down -Access-Control-Allow-Headers
# 传递原始客户端信息
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
# 保持连接活跃(提高性能)
transport http {
keepalive 30s
}
}
# 添加安全头部
header {
X-Frame-Options "DENY"
X-Content-Type-Options "nosniff"
Referrer-Policy "no-referrer-when-downgrade"
}
}

View File

@@ -0,0 +1,24 @@
前端页面部署,在/config/caddy.d目录下
xxx.com { # 你的前端域名
root * /usr/share/caddy
# 静态资源JS、CSS、图片等缓存 1 年
@static {
path *.js *.css *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2
}
header @static Cache-Control "public, max-age=259200, immutable"
# HTML 文件不缓存
@html {
path *.html
}
header @html Cache-Control "no-cache, no-store, must-revalidate"
# 静态文件需要的
file_server
# 也可以直接在这里反向代理后端
}

32
docker/docker-compose.yml Normal file
View File

@@ -0,0 +1,32 @@
version: "3.9"
services:
caddy:
image: caddy:2-alpine
container_name: caddy-rp
restart: unless-stopped
ports:
- "80:80"
- "443:443"
environment:
TZ: "Asia/Shanghai" # 设置时区为上海时区
volumes:
# 主配置
- /docker/caddy/volume/config/Caddyfile:/etc/caddy/Caddyfile
# 子配置目录
- /docker/caddy/volume/config/caddy.d:/etc/caddy/sites-enabled
# 站点文件目录
- /docker/caddy/volume/html:/usr/share/caddy
# 证书持久化
- /docker/caddy/volume/caddy_data:/data
- /docker/caddy/volume/caddy_config:/config
mybiji:
image: biji-houdaun:0.0.1-SNAPSHOT
container_name: mybiji
restart: unless-stopped
ports:
- "8084:8084"
volumes:
- /docker/biji-houduan/data:/data