温馨提示×

linux gitlab域名怎么设

小樊
44
2026-09-25 18:04:59
栏目: 云计算

在 Linux 上搭建 GitLab 后,设置“域名”通常包含 系统主机名、GitLab 外部访问地址、以及 DNS / Nginx 配置。下面按常见场景说明。


一、最常用:修改 GitLab 访问域名(external_url)

GitLab 的域名主要通过配置文件指定。

1. 编辑 GitLab 配置

sudo vim /etc/gitlab/gitlab.rb

找到或添加:

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

或 HTTPS:

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

⚠️ 域名不要带末尾 /


2. 重新加载配置

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

之后访问:

http://gitlab.example.com

二、设置服务器主机名(可选但推荐)

查看当前主机名

hostname

修改主机名

sudo hostnamectl set-hostname gitlab.example.com

或:

sudo vim /etc/hostname

三、本地测试用(无真实域名)

如果你只是内网或本地测试:

修改 hosts 文件

sudo vim /etc/hosts

添加:

192.168.1.100 gitlab.example.com

浏览器访问:

http://gitlab.example.com

四、真实域名(公网)

1. 域名解析

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

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

2. 防火墙

sudo ufw allow 80
sudo ufw allow 443

五、启用 HTTPS(推荐)

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

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

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

然后:

sudo gitlab-ctl reconfigure

六、Docker 版 GitLab 设置域名

docker run -d \
  --hostname gitlab.example.com \
  -p 80:80 -p 443:443 \
  -v gitlab-config:/etc/gitlab \
  gitlab/gitlab-ee

再改 /etc/gitlab/gitlab.rb 里的 external_url


七、常见问题

1. 页面显示 IP 而不是域名

✅ 检查 external_url 是否配置正确

2. 502 错误

✅ 端口冲突(80/443 被占用)

3. 修改域名后克隆地址不变

✅ 清缓存或重启:

sudo gitlab-ctl restart

如果你愿意,可以告诉我:

  • ✅ 是 源码 / Omnibus / Docker
  • ✅ 内网还是公网
  • ✅ 是否用 HTTPS

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

0 踩