在 Linux 上搭建 GitLab 后,设置“域名”通常包含 系统主机名、GitLab 外部访问地址、以及 DNS / Nginx 配置。下面按常见场景说明。
GitLab 的域名主要通过配置文件指定。
sudo vim /etc/gitlab/gitlab.rb
找到或添加:
external_url 'http://gitlab.example.com'
或 HTTPS:
external_url 'https://gitlab.example.com'
⚠️ 域名不要带末尾
/
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
之后访问:
http://gitlab.example.com
hostname
sudo hostnamectl set-hostname gitlab.example.com
或:
sudo vim /etc/hostname
如果你只是内网或本地测试:
sudo vim /etc/hosts
添加:
192.168.1.100 gitlab.example.com
浏览器访问:
http://gitlab.example.com
在域名服务商处添加 A 记录:
gitlab.example.com -> 服务器公网IP
sudo ufw allow 80
sudo ufw allow 443
external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
然后:
sudo gitlab-ctl reconfigure
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
✅ 检查 external_url 是否配置正确
✅ 端口冲突(80/443 被占用)
✅ 清缓存或重启:
sudo gitlab-ctl restart
如果你愿意,可以告诉我:
我可以给你精确配置示例。