在 Linux 上修改 GitLab 的端口,通常分为两种情况:Web 访问端口(HTTP/HTTPS) 和 SSH 端口。下面分别说明。
sudo vi /etc/gitlab/gitlab.rb
例如改成 8080:
external_url 'http://your-domain-or-ip:8080'
如果是 HTTPS:
external_url 'https://your-domain-or-ip:8443'
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
(或 ufw allow 8080)
sudo vi /etc/gitlab/gitlab.rb
例如改成 2222:
gitlab_rails['gitlab_shell_ssh_port'] = 2222
sudo gitlab-ctl reconfigure
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
如果 Linux 系统 SSH 端口改了(/etc/ssh/sshd_config),但 GitLab 还是用 22:
gitlab_rails['gitlab_shell_ssh_port'] = 你的系统SSH端口
sudo gitlab-ctl status
浏览器访问:
http://服务器IP:8080
reconfigure如果你告诉我:
我可以给你更精确的命令。