在 GitLab(Linux) 上配置 SSL(HTTPS),常见有三种方式,最推荐的是 使用 Let’s Encrypt 自动证书,其次是 使用自定义证书。
下面按 最常见场景 给你一套完整配置流程(适用于 Omnibus GitLab)。
gitlab.example.comping gitlab.example.com
必须能解析到 GitLab 服务器公网 IP。
sudo vim /etc/gitlab/gitlab.rb
添加或修改以下内容:
external_url "https://gitlab.example.com"
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
letsencrypt['auto_renew'] = true
✅ 不要手动配置 nginx['ssl_certificate']
✅ 不要手动配置 80/443 端口
sudo gitlab-ctl reconfigure
GitLab 会自动:
浏览器访问:
https://gitlab.example.com
假设你有:
gitlab.example.com.crt
gitlab.example.com.key
放到:
/etc/gitlab/ssl/
sudo mkdir -p /etc/gitlab/ssl
sudo cp gitlab.example.com.crt /etc/gitlab/ssl/
sudo cp gitlab.example.com.key /etc/gitlab/ssl/
sudo chmod 600 /etc/gitlab/ssl/gitlab.example.com.key
external_url "https://gitlab.example.com"
nginx['enable'] = true
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
nginx['redirect_http_to_https'] = true
然后:
sudo gitlab-ctl reconfigure
# Ubuntu
sudo ufw allow 80
sudo ufw allow 443
# CentOS
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
GitLab 会:
查看续期状态:
sudo gitlab-ctl renew-le-certs
sudo gitlab-ctl tail nginx
常见原因:
如果你用的是:
告诉我,我可以给你 对应版本的 SSL 配置方案。
如果你愿意,可以直接把下面信息发我,我可以帮你精确配置: