Files
gitea/README.md
tech af7d49b685 switch to Caddy reverse proxy with auto HTTPS
Replace manual nginx + SSL certificates with Caddy for automatic
Let's Encrypt certificate management. Remove direct HTTP port exposure,
route web traffic through Caddy (80/443) via Docker internal network.
SSH remains on port 2222.
2026-04-23 21:05:07 +08:00

113 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Gitea Docker 部署Caddy 反向代理 + 自动 HTTPS
使用 Docker Compose 部署 Gitea通过 Caddy 反向代理实现自动 HTTPSLet's Encrypt
## 架构
```
Client → Caddy (80/443, 自动 HTTPS) → Gitea (3000, Docker 内部网络)
Gitea SSH (22 → 宿主机 2222)
```
- **Caddy** 处理 HTTPS 证书的自动申请、续期和 HTTP→HTTPS 重定向
- **Gitea** Web 流量通过 Docker 内部网络由 Caddy 代理,不直接暴露端口
- **SSH** 直接映射到宿主机 2222 端口,不经过 Caddy
## 快速开始
### 前提条件
- 域名已解析到服务器公网 IP
- 服务器 80、443、2222 端口可从外网访问
### 1. 配置环境变量
```bash
cp .env.example .env
```
编辑 `.env`,关键配置:
```env
DOMAIN=git.example.com # 你的域名Caddy 将为此域名申请 HTTPS 证书)
SSH_PORT=2222 # SSH 端口(宿主机端口,容器内仍为 22
```
> `GITEA__server__SSH_PORT` 通过 `.env` 传递给容器,使 Web 界面中的 SSH clone 地址正确显示端口号。
### 2. 启动服务
```bash
docker compose up -d
```
Caddy 会自动为 `DOMAIN` 申请 Let's Encrypt 证书,稍等片刻后即可通过 HTTPS 访问。
### 3. 初始配置
首次访问 `https://<DOMAIN>` 会进入安装向导:
1. 设置管理员账户
2. 数据库已默认使用 SQLite
## 访问方式
| 方式 | 地址 |
|-----|------|
| Web 界面 | `https://<DOMAIN>` |
| HTTPS 克隆 | `git clone https://<DOMAIN>/<用户>/<仓库>.git` |
| SSH 克隆 | `git clone ssh://git@<DOMAIN>:2222/<用户>/<仓库>.git` |
## Git LFS
已启用 Git LFS 支持,使用方法:
```bash
git lfs install
git lfs track "*.psd"
git add .gitattributes
git commit -m "Track PSD files with LFS"
git push
```
## 数据备份
备份 `data/` 目录:
```bash
# 备份
tar -czvf gitea-backup-$(date +%Y%m%d).tar.gz data/
# 恢复
tar -xzvf gitea-backup-20260320.tar.gz
```
重要文件:
- `data/gitea/gitea.db` - 用户和配置数据
- `data/git/repositories/` - 仓库数据
- `data/git/lfs/` - LFS 文件
## 常用命令
```bash
# 启动
docker compose up -d
# 停止
docker compose down
# 查看日志
docker compose logs -f
# 查看 Caddy 日志
docker compose logs -f caddy
# 重启
docker compose restart
# 更新版本
# 修改 .env 中的 GITEA_VERSION 后
docker compose up -d
```