在Ubuntu上配置GitLab的SSL证书,可参考以下步骤:
安装Certbot工具:
sudo apt update
sudo apt install certbot python3-certbot-nginx
获取SSL证书:
替换yourdomain.com为实际域名,运行命令:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
按提示输入邮箱并同意服务条款,Certbot会自动配置Nginx。
配置GitLab使用SSL:
编辑配置文件/etc/gitlab/gitlab.rb:
sudo nano /etc/gitlab/gitlab.rb
找到并修改以下内容:
external_url 'https://yourdomain.com'
nginx['redirect_http_to_https'] = true # 可选:强制HTTP跳转HTTPS
保存后退出。
重新配置并重启GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
验证SSL配置:
打开浏览器访问https://yourdomain.com,确认证书正确安装且页面可正常访问。
(可选)配置证书自动续期:
编辑/etc/gitlab/gitlab.rb,添加以下内容(设置续期时间和频率):
letsencrypt['auto_renew'] = true
letsencrypt['auto_renew_hour'] = "12"
letsencrypt['auto_renew_minute'] = "30"
保存后重启GitLab使配置生效。
说明:以上步骤基于Let’s Encrypt免费证书,适用于Nginx环境。若使用其他证书或代理,需调整nginx['ssl_certificate']等参数指向证书路径。