Linux 上 GitLab 出现 502 错误,通常意味着 GitLab 的前端(Nginx)能访问,但后端服务(如 Unicorn / Puma / Sidekiq)无法正常响应。下面按最常见原因 → 排查方法 → 解决方式给你系统说明。
刚重启或服务器重启后,GitLab 还在启动中。
检查:
sudo gitlab-ctl status
现象:
unicorn / puma 不是 runsidekiq 未运行解决:
sudo gitlab-ctl restart
# 或
sudo gitlab-ctl start
等待 1–2 分钟再访问。
GitLab 非常吃内存,低于 2GB 极易 502。
检查内存:
free -h
查看是否被杀:
dmesg | grep -i oom
解决:
GitLab 默认:
80808080检查端口:
ss -lntp | grep 8080
如果没有监听 → 服务挂了。
查看 Nginx 错误日志:
sudo tail -n 50 /var/log/gitlab/nginx/gitlab_error.log
常见错误:
connect() failed (111: Connection refused) while connecting to upstream
说明后端没起来。
常见于:
gitlab.rb检查配置:
sudo gitlab-ctl reconfigure
如果报错,按提示修复。
GitLab 对磁盘很敏感。
df -h
如果 /var/opt/gitlab 满了:
# 1. 看服务状态
sudo gitlab-ctl status
# 2. 看主要日志
sudo gitlab-ctl tail
# 3. 看 Nginx
sudo tail -f /var/log/gitlab/nginx/gitlab_error.log
# 4. 内存
free -h
| GitLab 版本 | 后端 |
|---|---|
| ≤ 13.x | Unicorn |
| ≥ 14.x | Puma |
新版本 502,重点看 Puma。
如果只是临时访问:
sudo gitlab-ctl restart puma
sudo gitlab-ctl restart nginx
你可以直接贴出以下信息之一:
gitlab-ctl status 输出gitlab_error.log 报错cat /opt/gitlab/version-manifest.txt)我可以直接帮你定位是哪一行配置或哪个服务导致 502。