温馨提示×

Debian GitLab如何配SSL

小樊
52
2026-10-05 11:08:11
栏目: 云计算

在 Debian 上部署的 GitLab 配置 SSL(HTTPS),通常有两种常见方式:


一、使用 Let’s Encrypt 免费证书(推荐)

1. 确保域名解析正确

  • 你的 GitLab 域名(如 gitlab.example.com)已解析到服务器 IP
  • 服务器 80、443 端口可访问

2. 修改 GitLab 配置

编辑配置文件:

sudo nano /etc/gitlab/gitlab.rb

修改或添加以下内容:

external_url 'https://gitlab.example.com'

letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
letsencrypt['auto_renew'] = true

⚠️ external_url 必须是 https://

3. 重新配置 GitLab

sudo gitlab-ctl reconfigure

4. 验证

浏览器访问:

https://gitlab.example.com

二、使用自有 SSL 证书(企业/内网常用)

1. 准备证书文件

通常需要:

  • 证书:gitlab.example.com.crt
  • 私钥:gitlab.example.com.key

放到安全目录,例如:

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/*

2. 修改 GitLab 配置

sudo nano /etc/gitlab/gitlab.rb
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"

3. 重新配置

sudo gitlab-ctl reconfigure

三、强制 HTTPS(可选)

nginx['redirect_http_to_https'] = true

四、常见问题

1. 端口冲突

GitLab 默认使用 80/443,若被占用:

nginx['listen_port'] = 443

2. 证书不信任(自签证书)

客户端需手动信任 CA 证书

3. 查看 Nginx 日志

sudo gitlab-ctl tail nginx

如果你能告诉我:

  • GitLab 安装方式(Omnibus / Docker / 源码)
  • 是否使用反向代理(Nginx / Caddy)
  • 内网还是公网

我可以给你更精确的配置示例。

0 踩