在 Linux 上部署的 GitLab 想要通过域名访问,一般需要做下面几步(以官方 Omnibus GitLab 为例,最常见):
git.example.com)在你的域名服务商处添加记录:
类型:A
主机记录:git
记录值:你的服务器公网IP
例如:
git.example.com → 1.2.3.4
编辑 GitLab 配置:
sudo vim /etc/gitlab/gitlab.rb
修改或添加以下内容:
external_url 'http://git.example.com'
如果你要用 HTTPS(推荐):
external_url 'https://git.example.com'
保存后执行:
sudo gitlab-ctl reconfigure
确保端口开放:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
云服务器还要在安全组放通 80 / 443。
如果你服务器上已有 Nginx:
nginx['enable'] = false
server {
listen 80;
server_name git.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
然后:
sudo gitlab-ctl reconfigure
sudo systemctl restart nginx
在 gitlab.rb 中:
letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true
重新配置:
sudo gitlab-ctl reconfigure
浏览器访问:
http://git.example.com
或
https://git.example.com
如果你能告诉我:
我可以给你更精确的配置示例。