温馨提示×

如何设置debian gitlab域名

小樊
44
2026-09-14 14:51:30
栏目: 云计算

在 Debian 上设置 GitLab 的域名,通常分为修改 GitLab 配置和配置 DNS / 反向代理两部分。下面按常见场景说明。


一、修改 GitLab 自身域名(最核心)

1. 编辑 GitLab 配置文件

sudo nano /etc/gitlab/gitlab.rb

找到或添加以下配置:

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

如果是 HTTP:

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

2. 重新配置 GitLab

sudo gitlab-ctl reconfigure

3. 重启相关服务(通常 reconfigure 已包含)

sudo gitlab-ctl restart

二、域名解析(DNS)

在你的域名服务商处添加记录:

如果是公网域名

A    gitlab.example.com    ->    服务器公网IP

如果是局域网 / 内网

  • 修改客户端 hosts 文件(Windows / Linux / macOS)
192.168.1.100 gitlab.example.com

三、使用 HTTPS(推荐)

1. 自动申请证书(Let’s Encrypt)

在 gitlab.rb 中:

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

然后:

sudo gitlab-ctl reconfigure

2. 使用自有证书

nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"

四、使用反向代理(Nginx / Caddy)

如果你不是用 GitLab 自带 Nginx:

1. 禁用 GitLab 的 Nginx

nginx['enable'] = false

2. 修改 GitLab 监听地址

gitlab_rails['trusted_proxies'] = ['127.0.0.1']
web_server['external_users'] = ['www-data']

3. 在反向代理中配置域名和 SSL


五、修改仓库 clone 地址显示

GitLab 会根据 external_url 自动生成:

git@gitlab.example.com:group/project.git

无需额外配置。


六、常见问题

1. 修改后页面打不开

  • 检查防火墙(80 / 443)
  • 检查 DNS 是否生效
  • 查看日志:
sudo gitlab-ctl tail nginx

2. 端口不是 80/443

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

如果你能告诉我:

  • ✅ 是 Omnibus GitLab 还是 Docker
  • ✅ 公网还是内网
  • ✅ 是否已用 Nginx 反代

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

0 踩