在 Debian 上部署的 GitLab 绑定域名,通常分为 修改 GitLab 配置 和 配置 Web 服务器(Nginx/Apache) 两部分。下面以 官方 Omnibus 包安装的 GitLab + Nginx 为例说明。
git.example.com)sudo vim /etc/gitlab/gitlab.rb
找到并修改以下内容:
external_url 'https://git.example.com'
如果是 HTTP:
external_url 'http://git.example.com'
sudo gitlab-ctl reconfigure
GitLab 默认使用自带的 Nginx,一般无需手动改 Nginx 配置。
如果你之前关闭过 GitLab 的 Nginx:
nginx['enable'] = false
那你需要自己配置反向代理(见下文)。
nginx['enable'] = false
sudo gitlab-ctl reconfigure
sudo apt install nginx
sudo vim /etc/nginx/sites-available/gitlab
示例配置:
server {
listen 80;
server_name git.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
启用站点:
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d git.example.com
Certbot 会自动修改 Nginx 配置并开启 HTTPS。
确保开放:
sudo ufw allow 80
sudo ufw allow 443
浏览器访问:
https://git.example.com
sudo gitlab-ctl status修改域名后需重启:
sudo gitlab-ctl restart
如果你使用的是 Docker 版 GitLab 或 GitLab CE 源码安装,可以告诉我,我可以给你对应方案。