温馨提示×

linux gitlab为何报502

小樊
39
2026-09-13 14:24:34
栏目: 智能运维

Linux 上 GitLab 报 502 Bad Gateway,通常是因为 GitLab 的前端代理(Nginx)无法连到后端服务(如 unicorn / pumasidekiq 等)。下面按最常见原因 → 排查方法 → 解决办法来说明。


一、最常见原因(90% 情况)

1️⃣ GitLab 服务没完全启动

gitlab-ctl status

如果看到 down 的服务( especially unicorn / puma / sidekiq

✅ 解决:

gitlab-ctl restart
# 或
gitlab-ctl start

2️⃣ 内存不足(非常常见)

GitLab 至少需要 4GB 内存,否则 Puma 会直接崩。

free -h

✅ 解决:

  • 加内存
  • 或限制 worker 数(见下文)

3️⃣ Puma / Unicorn 端口未监听

netstat -tunlp | grep 8080
# 或
ss -lntp | grep puma

如果没有监听,说明后端没起来。


4️⃣ Nginx 无法访问后端

日志路径:

/var/log/gitlab/nginx/gitlab_error.log

常见错误:

connect() failed (111: Connection refused) while connecting to upstream

说明 Nginx → Puma 不通


二、快速排查流程(推荐)

✅ 步骤 1:看 GitLab 日志

gitlab-ctl tail

重点看:

  • puma
  • unicorn
  • sidekiq
  • nginx

✅ 步骤 2:检查配置

gitlab-ctl reconfigure

如果配置错误,也会 502。


✅ 步骤 3:检查端口冲突

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 status
  • gitlab_error.log
  • 服务器内存

我可以帮你精准定位是哪一步出问题

0