在 Ubuntu 上给 GitLab 配置域名,通常分为 GitLab 自身配置 和 Web 服务器 / DNS 配置 两部分。下面以 官方 Omnibus GitLab 为例说明(最常见)。
gitlab.example.com)sudo vim /etc/gitlab/gitlab.rb
找到并修改:
external_url 'http://gitlab.example.com'
或使用 HTTPS:
external_url 'https://gitlab.example.com'
⚠️ 如果你用 HTTPS,建议让 GitLab 自动申请证书(见下文)
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
在 gitlab.rb 中:
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
然后:
sudo gitlab-ctl reconfigure
GitLab 会自动申请并配置 SSL。
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
证书目录需存在:
sudo mkdir -p /etc/gitlab/ssl
确保端口开放:
sudo ufw allow 80
sudo ufw allow 443
在你的域名服务商处:
Agitlab你的服务器IP示例:
gitlab.example.com → 1.2.3.4
浏览器访问:
https://gitlab.example.com
或命令行:
curl -I https://gitlab.example.com
external_url 已修改并 reconfigureexternal_url 'https://gitlab.example.com:8080'
需映射端口并配置 GITLAB_OMNIBUS_CONFIG 中的 external_url
如果你的情况是:
可以告诉我,我给你对应方案。