UNIXETC

使用gitea自建git服务

目录

安装git和sqlite #

1
apt install git sqlite3 -y

安装gitea #

下载地址在此 https://dl.gitea.com/gitea/

1
2
3
wget -O gitea https://dl.gitea.com/gitea/1.19.3/gitea-1.19.3-linux-amd64
chmod +x gitea
mv gitea /usr/local/bin/gitea

添加git用户 #

1
adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git User' git

新建目录 #

1
2
3
4
5
6
7
8
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini
export GITEA_WORK_DIR=/var/lib/gitea/

设置systemd服务 #

1
2
3
4
5
## 备份链接 https://unixetc.com/res/gitea.service
wget https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/systemd/gitea.service
cp gitea.server /etc/systemd/system/gitea.service
sudo systemctl enable gitea
sudo systemctl start gitea

配置gitea #

通过http://ip:3000来访问gitea web进行初始配置。

以下为[server]字段相关配置:

1
2
3
4
5
6
7
8
cat /etc/gitea/app.ini

[server]
SSH_DOMAIN       = gits.zip
DOMAIN           = gits.zip
ROOT_URL  = https://gits.zip/
HTTP_PORT = 3000
ENABLE_GZIP = true

配置完成后即可使用,当前访问方式为http://ip:port,https域名方式继续看下文。

安装caddy设置反向代理 #

1
2
3
4
5
apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install caddy

/etc/caddy/Caddyfile配置内容如下:

1
2
3
gits.zip {
        reverse_proxy localhost:3000
}

修改配置后使用systemctl restart caddy即可生效。