温馨提示×

centos gitlab如何SSL

小樊
45
2026-10-17 12:36:33
栏目: 云计算

在 CentOS 上部署 GitLab 并配置 SSL(HTTPS),常见有 两种方式:


一、使用 GitLab 自带的 Nginx(推荐,最简单)

1. 安装 GitLab(以 CentOS 7/8 为例)

sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

2. 准备 SSL 证书

把证书放到:

/etc/gitlab/ssl/

例如:

/etc/gitlab/ssl/gitlab.example.com.crt
/etc/gitlab/ssl/gitlab.example.com.key

证书可以是:

  • 免费 Let’s Encrypt
  • 自建 CA
  • 商业证书

3. 修改 GitLab 配置

编辑:

sudo vi /etc/gitlab/gitlab.rb

修改内容:

external_url 'https://gitlab.example.com'

nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"

4. 重新配置 GitLab

sudo gitlab-ctl reconfigure

访问:

https://gitlab.example.com

二、使用 Let’s Encrypt 免费 SSL(自动)

1. 修改配置

external_url 'https://gitlab.example.com'

letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']

2. 重新配置

sudo gitlab-ctl reconfigure

GitLab 会自动申请并配置证书。


三、使用外部 Nginx / Apache 反向代理(进阶)

如果你已有 Nginx:

server {
    listen 443 ssl;
    server_name gitlab.example.com;

    ssl_certificate     /etc/nginx/ssl/gitlab.crt;
    ssl_certificate_key /etc/nginx/ssl/gitlab.key;

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

GitLab 关闭自带 Nginx:

nginx['enable'] = false

四、常见问题

1. 浏览器提示证书不安全

  • 证书域名不一致
  • 使用了自签名证书(需手动信任)

2. 端口冲突

GitLab 默认:

  • 80 / 443(Nginx)
  • 8080(Unicorn / Puma)

3. SELinux 问题

sudo setsebool -P httpd_can_network_connect 1

五、推荐方案

✅ CentOS + GitLab 自带 Nginx + Let’s Encrypt

如果你愿意,我可以:

  • 帮你写 完整的一步一步命令
  • 或根据你的 CentOS 版本 / GitLab 版本 定制配置

0 踩