下面按常见场景给你说明:在 Linux 服务器上部署 GitLab 并配置 SSL(HTTPS)。以 Omnibus GitLab(官方包) 为例,这是最常见、最推荐的方式。
你有几种方式获取证书:
GitLab 自带支持。
gitlab.example.com.crtgitlab.example.com.key编辑配置文件:
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
保存后执行:
sudo gitlab-ctl reconfigure
✅ GitLab 会自动申请并配置证书
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['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 ufw allow 80
sudo ufw allow 443
或(CentOS / Rocky):
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
curl -I https://gitlab.example.com
浏览器访问:
https://gitlab.example.com
sudo netstat -tulnp | grep 80
告诉我你用的是:
我可以给你对应版本的 SSL 配置示例。
需要我帮你写一份完整可复制的 gitlab.rb 示例吗?