温馨提示×

ubuntu gitlab如何换端口

小樊
35
2026-10-07 17:58:14
栏目: 智能运维

在 Ubuntu 上修改 GitLab 的端口,通常分为 修改 GitLab 自身监听端口 和 修改 Nginx / 外部访问端口 两种情况。下面按常见场景说明。


一、修改 GitLab 自带的 Nginx 端口(最常用)

1. 编辑 GitLab 配置文件

sudo vim /etc/gitlab/gitlab.rb

2. 修改以下配置(示例改为 8081)

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

# 如果使用的是 GitLab 自带 Nginx
nginx['listen_port'] = 8081

如果是 HTTPS:

external_url 'https://your-domain-or-ip:8443'
nginx['listen_port'] = 8443
nginx['listen_https'] = true

3. 重新配置 GitLab

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

二、如果使用系统 Nginx(非 GitLab 内置)

1. 禁用 GitLab 内置 Nginx

nginx['enable'] = false

2. 修改 GitLab 监听端口(Unicorn / Puma)

puma['port'] = 8082
# 老版本可能是
# unicorn['port'] = 8082

3. 配置系统 Nginx

server {
    listen 8081;
    server_name your-domain-or-ip;

    location / {
        proxy_pass http://127.0.0.1:8082;
    }
}

4. 重载服务

sudo gitlab-ctl reconfigure
sudo systemctl restart nginx

三、修改 SSH 端口(可选)

默认 GitLab SSH 是 22,如需修改:

gitlab_rails['gitlab_shell_ssh_port'] = 2222

客户端使用:

git clone ssh://git@ip:2222/group/project.git

四、防火墙放行端口

sudo ufw allow 8081
# 或
sudo iptables -I INPUT -p tcp --dport 8081 -j ACCEPT

五、验证

sudo gitlab-ctl status
netstat -tulnp | grep 8081

如果你能告诉我:

  • GitLab 版本
  • 是否使用 Docker
  • 是否用 HTTPS

我可以给你更精确的配置示例。

0 踩