在 CentOS 上给 GitLab 配置域名,通常有两种常见场景:
下面以 GitLab 自带 Nginx(最常用) 为例说明。
git.example.com)编辑 GitLab 配置:
sudo vim /etc/gitlab/gitlab.rb
找到或添加:
external_url 'http://git.example.com'
如果是 HTTPS:
external_url 'https://git.example.com'
把证书放到服务器,例如:
/etc/gitlab/ssl/git.example.com.crt
/etc/gitlab/ssl/git.example.com.key
在 gitlab.rb 中:
nginx['ssl_certificate'] = "/etc/gitlab/ssl/git.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/git.example.com.key"
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
GitLab 会自动申请和续期证书。
每次修改配置后都必须执行:
sudo gitlab-ctl reconfigure
重启服务(可选):
sudo gitlab-ctl restart
确保防火墙允许:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
浏览器访问:
http://git.example.com
或
https://git.example.com
查看状态:
sudo gitlab-ctl status
例如改成 8080:
external_url 'http://git.example.com'
nginx['listen_port'] = 8080
如果你用外部 Nginx 反向代理,我可以单独给你一份配置。
如果你愿意,可以告诉我:
我可以直接给你一份可复制的配置。