Apache部署Git远程操作报500错误,权限配置排查求助
问题:Git HTTPS克隆报500内部错误,SSH正常,非www-data用户无法通过HTTPS访问
问题现象
- 本地克隆、推送仓库操作完全正常
- 通过HTTPS远程执行
git clone https://<域名>/testrepo.git时,返回500内部服务器错误 - 使用SSH方式(如
git clone ssh://jason@<域名>:/home/jason/domains/<域名>/public_html/testrepo.git)可正常完成操作
已排查内容
- Apache的
alias和cgi模块已安装并启用,CGI功能验证正常 - Ubuntu防火墙已开放80、443端口
- 将默认Apache错误日志调至debug级别后,未发现相关报错
更新:错误日志详情
查看站点专属错误日志/var/log/<域名>_error.log,发现以下关键错误:
Thu Aug 01 21:15:55.438216 2024] [cgi:error] [pid 7583] [client <ip>] AH01215: fatal: detected dubious ownership in repository at '/home/jason/domains/<域名>/public_html/testrepo.git': /usr/lib/git-core/git-http-backend [Thu Aug 01 21:15:55.438441 2024] [cgi:error] [pid 7583] [client <ip>] AH01215: To add an exception for this directory, call:: /usr/lib/git-core/git-http-backend [Thu Aug 01 21:15:55.438539 2024] [cgi:error] [pid 7583] [client <ip>] AH01215: : /usr/lib/git-core/git-http-backend [Thu Aug 01 21:15:55.438690 2024] [cgi:error] [pid 7583] [client <ip>] AH01215: git config --global --add safe.directory /home/jason/domains/<域名>/public_html/testrepo.git: /usr/lib/git-core/git-http-backend
已执行的尝试操作
- 运行命令
git config --global --add safe.directory /home/jason/domains/<域名>/public_html/testrepo.git,将仓库目录设为Git安全目录,但问题未解决 - 测试将仓库所有者改为
www-data后,HTTPS操作恢复正常,但希望使用自身管理用户(已加入www-data组,拥有sudo权限)进行仓库管理,而非切换到Apache默认用户
疑问
Git是否必须使用Apache默认用户运行?当前配置还遗漏了什么?
服务器基础配置
- Ubuntu Server 20.04
- Git version 2.25.1
- Apache2 version 2.4.41 (Ubuntu)
当前Apache虚拟主机配置
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin webmaster@localhost DocumentRoot /home/jason/domains/<域名>/public_html ServerName <域名> ServerAlias <域名> ErrorLog ${APACHE_LOG_DIR}/<域名>_error.log CustomLog ${APACHE_LOG_DIR}/<域名>_access.log combined # Directory settings for public_html <Directory /home/jason/domains/<域名>/public_html> Options +ExecCGI +FollowSymLinks AllowOverride None Require all granted </Directory> # Git HTTP backend configuration ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ SetEnv GIT_PROJECT_ROOT /home/jason/domains/<域名>/public_html SetEnv GIT_HTTP_EXPORT_ALL <Directory /usr/lib/git-core> Options +ExecCGI +FollowSymLinks AllowOverride None Require all granted </Directory> Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/<域名>/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/<域名>/privkey.pem </VirtualHost> </IfModule>
内容的提问来源于stack exchange,提问作者Jason Bassett
相关产品推荐
相关产品推荐

