Access
- 打开浏览器,访问:
https://<SERVER_IP> - 浏览器出现 SSL 警告属于正常现象(自签名证书)
- 注册新账号
- 首个注册账号将成为管理员
禁用自助注册(可选)
默认情况下,用户自助注册处于启用状态。
1. 编辑配置文件: /etc/gogs/conf/app.ini
2. Under the [auth] section, change: DISABLE_REGISTRATION = false to DISABLE_REGISTRATION = true
3. Restart Gogs:
systemctl restart gogs
重要文件与目录
- Install directory:
/opt/gogs - Configuration file:
/etc/gogs/conf/app.ini - Application data:
/var/lib/gogs - Repositories:
/var/lib/gogs/repositories - Logs:
/var/log/gogs - Systemd service:
/etc/systemd/system/gogs.service - Nginx config:
/etc/nginx/sites-available/gogs.conf - TLS certificates:
/etc/nginx/ssl/
Git Usage
HTTPS(自签名证书):
GIT_SSL_NO_VERIFY=true git clone https://<SERVER_IP>/<USERNAME>/<REPOSITORY>.git
SSH(内置服务器):
git clone ssh://git@<SERVER_IP>:2222/<USERNAME>/<REPOSITORY>.git
Service Management
Gogs:
systemctl status gogs
systemctl restart gogs
Nginx:
systemctl status nginx
systemctl restart nginx
PostgreSQL:
systemctl status postgresql
systemctl restart postgresql
Notes
- 主配置文件位于
/etc/gogs/conf/app.ini。修改配置文件后,使用以下命令重启服务:systemctl restart gogs. - Nginx 上传限制定义于
/etc/nginx/sites-available/gogs.confusingclient_max_body_size。对于大型仓库,请增大该值并重启 Nginx。 - 对于大规模部署,你可以取消注释
LimitMEMLOCK=infinityandLimitNOFILE=65535in/etc/systemd/system/gogs.service, then runsystemctl daemon-reload并重启 Gogs。 - 数据库凭据定义在
/etc/gogs/conf/app.ini. - 在生产环境中,建议将自签名证书替换为有效的 Let's Encrypt 证书。
- 如果使用自签名证书,HTTPS 克隆需要
GIT_SSL_NO_VERIFY=true.
通过域名启用 SSL
1. 将你的域名指向服务器 IP。
2. 更新 Gogs 配置(/etc/gogs/conf/app.ini):
EXTERNAL_URL = https://yourdomain.com/
DOMAIN = yourdomain.com
SSH_DOMAIN = yourdomain.com
3. 重启 Gogs 服务以应用更改:
systemctl restart gogs
3. 编辑 Nginx 配置,将以下两处 server_name <IP>; 使用您的域名(<your-domain>) 适用于 HTTP(端口 80)和 HTTPS(端口 443)的规则块:
vim /etc/nginx/sites-available/gogs.conf
4. Install Certbot:
apt install -y certbot python3-certbot-nginx
5. 运行以下命令生成有效的 Let's Encrypt 证书:
certbot certonly --nginx --non-interactive --agree-tos --email [email protected] -d yourdomain.com
6. 将 Nginx 配置中的 SSL 路径替换为:
vim /etc/nginx/sites-available/gogs.conf
# Before:
# ssl_certificate /etc/nginx/ssl/gogs.crt;
# ssl_certificate_key /etc/nginx/ssl/gogs.key;
# After:
# ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
7. 重启 Nginx 以应用更改:
systemctl restart nginx
8. 打开浏览器,访问: https://yourdomain.com