You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自建GitLab克隆/拉取时URL末尾自动加斜杠致403错误求助

解决GitLab克隆URL自动添加尾斜杠导致403的问题

问题原因

Apache反向代理配置中,ProxyPass目标路径带尾斜杠,会让Apache将.git结尾的请求识别为目录,自动触发301重定向到带尾斜杠的URL;而GitLab的仓库访问端点不接受xxx.git/格式的路径,因此返回403错误。

解决方案

1. 修正Apache反向代理配置

修改443虚拟主机中的ProxyPass和ProxyPassReverse,移除目标路径末尾的斜杠,并添加必要的转发头:

<VirtualHost *:443>
  SSLEngine On
  SSLCertificateFile /etc/apache2/certs/wildcard.crt
  SSLCertificateKeyFile /etc/apache2/certs/wildcard.key
  SSLCertificateChainFile /etc/apache2/certs/wildcard_bundle_ca.crt

  ServerName gitlab.example.net
  ProxyPreserveHost On
  # 移除目标路径末尾的斜杠
  ProxyPass / http://123.456.1.234:10080
  ProxyPassReverse / http://123.456.1.234:10080

  # 添加必要的转发头,让GitLab识别原始请求协议和客户端IP
  RequestHeader set X-Forwarded-Proto "https"
  RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s"

  ProxyRequests     Off
  AllowEncodedSlashes NoDecode
</VirtualHost>

2. 配置GitLab外部URL(Docker部署)

进入GitLab容器或修改gitlab.rb配置文件,确保外部URL正确设置,且内部nginx禁用HTTPS:

external_url 'https://gitlab.example.net'
nginx['listen_port'] = 10080
nginx['listen_https'] = false

如果是Docker部署,可通过以下命令进入容器修改配置:

docker exec -it <your-gitlab-container-name> editor /etc/gitlab/gitlab.rb

修改后执行配置生效命令:

docker exec -it <your-gitlab-container-name> gitlab-ctl reconfigure

3. 重启服务使配置生效

# 重启Apache
sudo systemctl restart apache2

# 重启GitLab容器
docker restart <your-gitlab-container-name>

内容的提问来源于stack exchange,提问作者user3562918

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 00:27:49