温馨提示×

gitlab在linux怎么换端口

小樊
39
2026-10-01 13:05:16
栏目: 智能运维

在 Linux 上修改 GitLab 的端口,通常分为两种情况:Web 访问端口(HTTP/HTTPS) 和 SSH 端口。下面分别说明。


一、修改 GitLab Web 端口(HTTP / HTTPS)

1. 编辑配置文件

sudo vi /etc/gitlab/gitlab.rb

2. 修改端口

例如改成 8080:

external_url 'http://your-domain-or-ip:8080'

如果是 HTTPS:

external_url 'https://your-domain-or-ip:8443'

3. 重新配置 GitLab

sudo gitlab-ctl reconfigure

4. 重启服务(可选)

sudo gitlab-ctl restart

5. 防火墙放行端口

sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

(或 ufw allow 8080)


二、修改 GitLab SSH 端口(默认 22)

1. 编辑配置文件

sudo vi /etc/gitlab/gitlab.rb

2. 修改 SSH 端口

例如改成 2222:

gitlab_rails['gitlab_shell_ssh_port'] = 2222

3. 重新配置

sudo gitlab-ctl reconfigure

4. 防火墙放行

sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload

三、如果你自己改了系统 SSH 端口(不是 GitLab)

如果 Linux 系统 SSH 端口改了(/etc/ssh/sshd_config),但 GitLab 还是用 22:

gitlab_rails['gitlab_shell_ssh_port'] = 你的系统SSH端口

四、验证

sudo gitlab-ctl status

浏览器访问:

http://服务器IP:8080

常见坑

  • 改了端口但没 reconfigure
  • 云服务器安全组没放行
  • Nginx 端口冲突
  • external_url 没写端口

如果你告诉我:

  • GitLab 安装方式(Omnibus / Docker)
  • 当前系统(CentOS / Ubuntu)
  • 想改哪个端口

我可以给你更精确的命令。

0 踩