在 CentOS 上给 GitLab 配置 SSL(HTTPS),常见有三种方式。下面以 Omnibus GitLab(官方 RPM 安装) 为例说明,最推荐、最简单。
例如:
gitlab.example.com -> 你的服务器IP
编辑配置文件:
sudo vim /etc/gitlab/gitlab.rb
添加或修改:
external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
sudo gitlab-ctl reconfigure
✅ 访问 https://gitlab.example.com 即可,证书自动签发和续期。
假设你有:
gitlab.example.com.crt
gitlab.example.com.key
放到目录:
sudo mkdir -p /etc/gitlab/ssl
sudo chmod 700 /etc/gitlab/ssl
sudo cp gitlab.example.com.crt /etc/gitlab/ssl/
sudo cp gitlab.example.com.key /etc/gitlab/ssl/
sudo vim /etc/gitlab/gitlab.rb
external_url 'https://gitlab.example.com'
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
sudo gitlab-ctl reconfigure
适合 GitLab 前面还有一层代理的情况。
external_url 'https://gitlab.example.com'
gitlab_rails['trusted_proxies'] = ['127.0.0.1']
nginx['listen_https'] = false
nginx['listen_port'] = 80
然后在外层 Nginx 配置 SSL 并反代到 GitLab。
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo setsebool -P httpd_can_network_connect on
curl -I https://gitlab.example.com
或使用浏览器查看证书信息。
❌ 证书不生效
external_url 是 https❌ Let’s Encrypt 失败
如果你愿意,可以告诉我:
我可以给你更精确的步骤。