温馨提示×

centos gitlab怎么SSL

小樊
42
2026-09-21 04:03:36
栏目: 云计算

下面以 CentOS 7/8 + 官方 GitLab(Omnibus 安装) 为例,说明如何给 GitLab 配置 HTTPS / SSL


一、准备 SSL 证书

你可以选择:

方式 1:使用 Let’s Encrypt(推荐)

GitLab 自带 Let’s Encrypt 支持。

方式 2:使用自有证书

例如:

  • gitlab.example.com.crt
  • gitlab.example.com.key

二、修改 GitLab 配置

编辑配置文件:

sudo vi /etc/gitlab/gitlab.rb

1️⃣ 设置域名

external_url 'https://gitlab.example.com'

注意:必须是 https


2️⃣ Let’s Encrypt 自动证书(推荐)

letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true
letsencrypt['contact_emails'] = ['admin@example.com']

3️⃣ 或 使用自有证书

nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"

证书目录需存在:

sudo mkdir -p /etc/gitlab/ssl
sudo chmod 600 /etc/gitlab/ssl/*

三、重新配置 GitLab

sudo gitlab-ctl reconfigure

四、防火墙 & 端口

确保放行:

sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

五、验证

浏览器访问:

https://gitlab.example.com

无证书警告即成功 ✅


六、常见问题

❌ 证书不受信任

  • 自签证书需手动导入
  • 或改用 Let’s Encrypt

❌ 端口冲突

GitLab 默认使用 80 / 443

❌ reconfigure 报错

查看日志:

sudo gitlab-ctl tail nginx

如果你告诉我:

  • CentOS 版本
  • GitLab 安装方式(源码 / Docker / Omnibus)
  • 是否使用域名

我可以给你更精确的步骤

0