Linux 上 GitLab 报 502 Bad Gateway,通常是因为 GitLab 的前端代理(Nginx)无法连到后端服务(如 unicorn / puma、sidekiq 等)。下面按最常见原因 → 排查方法 → 解决办法来说明。
gitlab-ctl status
如果看到 down 的服务( especially unicorn / puma / sidekiq)
✅ 解决:
gitlab-ctl restart
# 或
gitlab-ctl start
GitLab 至少需要 4GB 内存,否则 Puma 会直接崩。
free -h
✅ 解决:
netstat -tunlp | grep 8080
# 或
ss -lntp | grep puma
如果没有监听,说明后端没起来。
日志路径:
/var/log/gitlab/nginx/gitlab_error.log
常见错误:
connect() failed (111: Connection refused) while connecting to upstream
说明 Nginx → Puma 不通
gitlab-ctl tail
重点看:
pumaunicornsidekiqnginxgitlab-ctl reconfigure
如果配置错误,也会 502。
lsof -i:80
lsof -i:8080
如果 8080 被占用,GitLab 起不来。
编辑:
vi /etc/gitlab/gitlab.rb
puma['worker_processes'] = 2
sidekiq['concurrency'] = 5
postgresql['shared_buffers'] = "256MB"
然后:
gitlab-ctl reconfigure
gitlab-ctl restart
| 原因 | 说明 |
|---|---|
| 磁盘满 | df -h |
| 时间不同步 | date |
| SELinux | getenforce |
| 防火墙 | firewalld / iptables |
| 升级失败 | gitlab-rake gitlab:check |
GitLab 502 = Nginx 连不上后端 = 服务没起 / 内存不够 / 配置错
如果你愿意,可以贴出:
gitlab-ctl statusgitlab_error.log我可以帮你精准定位是哪一步出问题。