在 Debian 上部署的 GitLab,如果你说的**“备域名”是指增加一个备用域名(让用户通过多个域名访问同一个 GitLab)**,可以通过修改 GitLab 配置来实现。
下面分几种常见情况说明。
编辑配置文件:
sudo vim /etc/gitlab/gitlab.rb
找到或添加以下内容:
external_url 'https://gitlab.example.com'
# 备用域名
gitlab_rails['gitlab_host'] = 'gitlab.example.com'
gitlab_rails['allowed_hosts'] = ['gitlab.example.com', 'gitlab.backup.com', 'gitlab2.example.net']
如果是 Omnibus GitLab(官方包),推荐这样写:
external_url 'https://gitlab.example.com'
nginx['server_name'] = 'gitlab.example.com gitlab.backup.com'
⚠️ 注意:
external_url只能写一个,但 Nginx 可以接受多个server_name
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
确保备用域名解析到同一台服务器 IP:
gitlab.example.com A 1.2.3.4
gitlab.backup.com A 1.2.3.4
如果你使用 Let’s Encrypt:
letsencrypt['enable'] = true
letsencrypt['domains'] = ['gitlab.example.com', 'gitlab.backup.com']
然后:
sudo gitlab-ctl reconfigure
如果是主备 GitLab(灾备),常见方案是:
gitlab.example.comgitlab-backup.example.com适用于 GitLab EE:
官方文档:
https://docs.gitlab.com/ee/geo/
用户 → backup.example.com → nginx → gitlab 主/备
需要在 allowed_hosts 中加入备域名。
gitlab_rails['gitlab_host'] = 'gitlab.example.com'
gitlab_rails['gitlab_port'] = 443
gitlab_rails['gitlab_https'] = true
nginx['server_name']如果你能说清楚:
我可以给你更精确的配置。