温馨提示×

linux gitlab怎么域名绑

小樊
38
2026-09-07 13:14:41
栏目: 云计算

下面按最常见场景给你说明:在 Linux 服务器上部署的 GitLab(Omnibus 安装)如何绑定域名


一、前提条件

  • GitLab 已安装(通常是 /etc/gitlab/gitlab.rb
  • 已有一个域名(如 git.example.com
  • 域名已解析到服务器公网 IP(A 记录)
  • 服务器防火墙开放 80 / 443

二、修改 GitLab 域名配置

1. 编辑配置文件

sudo vim /etc/gitlab/gitlab.rb

2. 修改外部访问地址

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

如果要 HTTPS

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

三、重新加载配置

sudo gitlab-ctl reconfigure

四、配置域名解析(DNS)

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

类型 主机记录
A git 服务器公网 IP

示例:

git.example.com → 1.2.3.4

等待生效(通常几分钟到几十分钟)


五、使用 Nginx(GitLab 自带)

GitLab 默认使用自带 Nginx,一般不用额外配置

如需修改端口:

nginx['listen_port'] = 80

六、启用 HTTPS(推荐)

方式 1:GitLab 自动签发(Let’s Encrypt)

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

然后:

sudo gitlab-ctl reconfigure

七、如果你用外部 Nginx / 反向代理

nginx['enable'] = false
web_server['external_users'] = ['www-data']

外部 Nginx 示例:

server {
    listen 80;
    server_name git.example.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
    }
}

八、验证

浏览器访问:

http://git.example.com

https://git.example.com

九、常见问题

  • 访问不了:检查安全组 / 防火墙
  • 502:GitLab 服务未完全启动
  • 域名不生效:DNS 未同步

如果你告诉我:

  • GitLab 安装方式(Omnibus / Docker / 源码)
  • 是否用 Docker
  • 是否已有 Nginx

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

0