Debian 上 GitLab 出现 502 错误,通常是因为 GitLab 的核心服务没有正常启动或响应超时。下面按「最常见原因 → 排查方法 → 解决方式」给你一个系统性的说明。
GitLab 依赖多个组件:
nginxgitlab-workhorsepuma(或 unicorn,老版本)sidekiqpostgresqlredis只要其中一个挂了,就会 502。
✅ 检查服务状态:
sudo gitlab-ctl status
正常应看到类似:
run: nginx: ...
run: puma: ...
run: sidekiq: ...
run: postgresql: ...
run: redis: ...
如果有 down,就是问题所在。
GitLab 官方建议 至少 4GB 内存,2GB 极易 502。
✅ 查看内存:
free -h
如果 swap 也没开,puma 很容易直接被 OOM 杀掉。
✅ 临时解决:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
查看日志:
sudo gitlab-ctl tail puma
# 或老版本
sudo gitlab-ctl tail unicorn
常见错误:
查看 nginx 日志:
sudo gitlab-ctl tail nginx
常见错误:
connect() failed (111: Connection refused) while connecting to upstream
说明 workhorse 没起来 或 端口不对。
如果你改过:
✅ 重新加载配置:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
# 1. 看状态
sudo gitlab-ctl status
# 2. 看日志
sudo gitlab-ctl tail
# 3. 重启
sudo gitlab-ctl restart
# 4. 确认内存
free -h
GitLab 对 Debian 版本敏感:
cat /etc/debian_version
支持的版本(示例):
老 GitLab + 新 Debian 容易炸。
sudo ufw status
确保:
是放行的。
你可以直接贴出以下信息之一:
sudo gitlab-ctl status 输出sudo gitlab-ctl tail 报错我可以帮你精确定位是哪一步出的问题。