在 Ubuntu 上给 GitLab 配置 SSL(HTTPS),常见有两种方式:
下面以 GitLab Omnibus(官方 apt 安装) 为例说明。
gitlab.example.comsudo ufw allow 80
sudo ufw allow 443
GitLab 自带 Let’s Encrypt 支持。
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
如果之前是 http,改成 https 后 GitLab 会自动重定向
sudo gitlab-ctl reconfigure
浏览器访问:
https://gitlab.example.com
/etc/gitlab/ssl/gitlab.example.com.crt
/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 gitlab-ctl reconfigure
Let’s Encrypt 验证需要 80 端口:
sudo netstat -tulnp | grep :80
手动测试:
sudo gitlab-rake letsencrypt:redo
确保:
gitlab-ctl reconfigure如果你用的是 Docker:
docker run -d \
--name gitlab \
-p 443:443 -p 80:80 \
-v /srv/gitlab/config:/etc/gitlab \
-v /srv/gitlab/ssl:/etc/gitlab/ssl \
gitlab/gitlab-ce
然后在 /srv/gitlab/config/gitlab.rb 中配置 SSL。
如果你愿意,可以告诉我:
我可以给你一份完全对应的配置示例。