在 CentOS 上部署 GitLab 出现 502 错误,通常不是 GitLab 本身坏了,而是后端服务没有正常响应(最常见是 Unicorn / Puma、Nginx、PostgreSQL、Redis 等问题)。下面按最常见原因 → 排查方法 → 解决方式来说明。
GitLab 启动慢,第一次访问 502 是正常的。
✅ 解决:
gitlab-ctl status
等待所有服务为 run 状态,尤其是:
unicorn 或 pumasidekiqnginxpostgresql一般等 1–3 分钟再访问。
GitLab 官方最低要求 4GB 内存,2GB 基本必 502。
✅ 检查:
free -h
如果 swap 也没,直接 OOM。
✅ 解决:
GitLab 内部服务没起来,Nginx 就会返回 502。
✅ 查看日志:
gitlab-ctl tail unicorn
# 或
gitlab-ctl tail puma
常见错误:
timeoutcannot bind portpermission denied比如:
✅ 检查:
gitlab-ctl tail nginx
netstat -lntp | grep 80
✅ 解决:
systemctl stop httpd
数据库挂了,GitLab 直接 502。
✅ 查看:
gitlab-ctl status postgresql
gitlab-ctl tail postgresql
df -h
GitLab 日志一多就爆盘。
✅ 解决:
gitlab-ctl cleanse
# 或清日志
# 1. 看整体状态
gitlab-ctl status
# 2. 看错误日志
gitlab-ctl tail
# 3. 看内存
free -h
# 4. 看端口
netstat -lntp
# 5. 重启(必要时)
gitlab-ctl restart
编辑:
vi /etc/gitlab/gitlab.rb
puma['worker_processes'] = 2
sidekiq['concurrency'] = 10
postgresql['shared_buffers'] = "256MB"
然后:
gitlab-ctl reconfigure
gitlab-ctl restart
CentOS GitLab 502 = 后端服务没起来 核心三件事:内存够、服务起、端口没冲突
如果你愿意,可以贴出:
gitlab-ctl statusgitlab-ctl tail 的最后 20 行我可以帮你精准定位是哪一步挂了。