下面以 Linux(Ubuntu / CentOS 常见场景)+ 自建 GitLab(Omnibus 安装) 为例,说明如何配置 SSL(HTTPS)。
你有几种常见方式:
sudo apt install certbot -y # Ubuntu
# 或
sudo yum install certbot -y # CentOS
生成证书(假设域名 gitlab.example.com):
sudo certbot certonly --webroot \
-w /var/opt/gitlab/nginx/www \
-d gitlab.example.com
证书路径:
/etc/letsencrypt/live/gitlab.example.com/fullchain.pem
/etc/letsencrypt/live/gitlab.example.com/privkey.pem
假设你已有:
/etc/gitlab/ssl/gitlab.example.com.crt
/etc/gitlab/ssl/gitlab.example.com.key
编辑 GitLab 配置文件:
sudo vim /etc/gitlab/gitlab.rb
external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
或(使用自有证书):
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
nginx['redirect_http_to_https'] = true
sudo gitlab-ctl reconfigure
重启(通常不需要,但可执行):
sudo gitlab-ctl restart
确保开放:
sudo ufw allow 443
sudo ufw allow 80
或(CentOS):
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
浏览器访问:
https://gitlab.example.com
无证书警告 ✅ 即配置成功。
sudo crontab -e
添加:
0 3 * * * /usr/bin/certbot renew --quiet && gitlab-ctl restart nginx
确保:
检查:
external_url 'https://...'
需将 CA 证书加入信任链。
如果你用的是:
可以告诉我具体环境,我可以给你更精确的配置。