在 Linux 上给 GitLab 开启 HTTPS,常见有三种方式,按使用频率从高到低说明。以下以 GitLab CE(Omnibus 安装) 为例(最常见)。
sudo vim /etc/gitlab/gitlab.rb
关键配置:
external_url "https://gitlab.example.com"
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['your@email.com']
letsencrypt['auto_renew'] = true
⚠️ 注意:
external_url必须是 https
sudo gitlab-ctl reconfigure
GitLab 会自动:
浏览器访问:
https://gitlab.example.com
假设你有:
/etc/gitlab/ssl/gitlab.example.com.crt
/etc/gitlab/ssl/gitlab.example.com.key
⚠️ 文件名必须和域名一致
sudo vim /etc/gitlab/gitlab.rb
external_url "https://gitlab.example.com"
nginx['enable'] = true
nginx['redirect_http_to_https'] = 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
external_url "https://gitlab.example.com"
nginx['redirect_http_to_https'] = true
然后:
sudo gitlab-ctl reconfigure
sudo ufw allow 443
sudo ufw allow 80
或(CentOS / RHEL):
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
✅ 解决:
sudo netstat -tulnp | grep :80
✅ 解决:使用 Let’s Encrypt 或更换正规 CA
openssl s_client -connect gitlab.example.com:443 | grep issuer
docker run -d \
-p 443:443 -p 80:80 \
-e GITLAB_HTTPS=true \
-e GITLAB_HOST=gitlab.example.com \
gitlab/gitlab-ce
| 场景 | 推荐方式 |
|---|---|
| 公网服务器 | ✅ Let’s Encrypt |
| 内网 / 企业 | ✅ 自定义证书 |
| 快速测试 | HTTP(不推荐) |
如果你愿意,可以告诉我:
我可以给你 精确到命令级别 的配置方案。