在 CentOS 上部署的 GitLab,如果你想通过域名访问(而不是 IP + 端口),通常有以下几种常见做法,取决于你是 GitLab Omnibus 安装 还是 Docker 安装。
下面以 最常见的情况:GitLab Omnibus(官方 RPM 安装) 为例说明。
gitlab.example.com)vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'
如果是 HTTPS(推荐):
external_url 'https://gitlab.example.com'
⚠️ 注意:
- 写
external_url后,GitLab 会自动占用 80 / 443 端口- 不要再手动改 nginx 端口
gitlab-ctl reconfigure
gitlab-ctl restart
比如:
nginx['listen_port'] = 8080
必须删掉或注释掉,否则域名访问会失败。
正确示例:
# nginx['listen_port'] = 8080
gitlab.example.com.crtgitlab.example.com.keyexternal_url 'https://gitlab.example.com'
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
创建目录并上传证书:
mkdir -p /etc/gitlab/ssl
重新配置:
gitlab-ctl reconfigure
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
setsebool -P httpd_can_network_connect 1
如果你是用 Docker:
docker run -d \
--name gitlab \
-p 80:80 -p 443:443 \
-e GITLAB_OMNIBUS_CONFIG="external_url 'https://gitlab.example.com'" \
gitlab/gitlab-ce
如果你愿意,可以告诉我:
我可以直接帮你写一份完整可用配置。