当 Ubuntu 服务器的 IP 地址改变 之后,GitLab 服务可能会出现以下问题:
-
Web 页面无法访问(因为
external_url
还指向旧 IP); -
SSH 克隆或推送失败(因为域名/IP 不匹配);
-
反向代理或 HTTPS 证书异常(如果有配置 Nginx / Let's Encrypt);
下面是 完整解决方案,你可以按情况一步步执行👇
一、确认新 IP
先确认新 IP 地址:
ip addr show
假设新 IP 是 192.168.1.100
。
二、修改 GitLab 配置文件
编辑配置文件:
sudo vim /etc/gitlab/gitlab.rb
找到这行:
external_url 'http://旧的_IP或域名'
改为:
external_url 'http://192.168.1.100'
⚠️ 如果你之前用的是 HTTPS 或域名(如
https://gitlab.example.com
),可以暂时保持 HTTPS 或改成新的域名。
三、重新配置 GitLab
修改后执行:
sudo gitlab-ctl reconfigure
这一步会重新生成配置并让服务识别新的 IP。
四、重启 GitLab 服务
sudo gitlab-ctl restart
等待 1~2 分钟后,用浏览器访问:
http://192.168.1.100
五、(可选)更新 Git 远程仓库地址
在客户端(开发者电脑上):
git remote -v
如果看到旧 IP:
origin http://192.168.1.50/root/test.git (fetch) origin http://192.168.1.50/root/test.git (push)
则改为新的:
git remote set-url origin http://192.168.1.100/root/test.git
六、(可选)如果使用了 HTTPS + Let's Encrypt
若之前使用自动签发证书:
letsencrypt['contact_emails'] = ['your@email.com']
IP 改变不会自动续签,你可以:
sudo gitlab-ctl reconfigure sudo gitlab-ctl restart
若仍失败,可以用域名方式访问,或重新签发证书。
七、(可选)如果使用自定义反向代理(Nginx、Traefik)
要同时更新代理配置中反向转发目标:
proxy_pass http://192.168.1.100:8080;
然后重启代理。
总结:
步骤 | 操作 | 命令 |
---|---|---|
1 | 修改 GitLab 外部 URL | sudo vim /etc/gitlab/gitlab.rb |
2 | 重新生成配置 | sudo gitlab-ctl reconfigure |
3 | 重启服务 | sudo gitlab-ctl restart |
4 | 更新客户端远程地址 | git remote set-url ... |