在Debian上为GitLab设置SSL证书,通常需要以下几个步骤:
你可以从多个来源获取SSL证书,例如:
安装Certbot:
sudo apt update
sudo apt install certbot python3-certbot-nginx
运行Certbot以获取证书:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
按照提示完成证书的获取和配置。
Certbot会自动修改Nginx配置文件以使用SSL证书。你需要确保GitLab的Nginx配置文件也被正确配置。
打开GitLab的Nginx配置文件:
sudo nano /etc/gitlab/gitlab.rb
确保以下配置项存在并正确设置:
external_url 'https://yourdomain.com'
nginx['ssl_certificate'] = "/etc/letsencrypt/live/yourdomain.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/yourdomain.com/privkey.pem"
保存并退出编辑器。
重新配置GitLab:
sudo gitlab-ctl reconfigure
确保Nginx正确地使用了SSL证书,并且GitLab可以通过HTTPS访问。
https://yourdomain.com。Let’s Encrypt证书每90天需要续期一次。Certbot会自动处理续期,但你可以通过以下命令手动测试续期过程:
sudo certbot renew --dry-run
如果没有错误,Certbot会在证书到期前自动续期。
确保防火墙允许HTTPS流量(端口443):
sudo ufw allow 443/tcp
最后,重启Nginx以确保所有更改生效:
sudo systemctl restart nginx
通过以上步骤,你应该能够在Debian上成功为GitLab设置SSL证书。