我一直在按照在 Windows 上用 Apache 托管 Git 服务器一切运行正常。然后我想为推送请求添加一个基本身份验证,因此按照给出的解决方案进行了更改这个问题到我的httpd.conf
文件并创建一个有密码的用户。
但当我尝试推送到我的存储库(在本地主机上)时,出现 403 错误。这可能是什么原因?
我的文件末尾的补充内容httpd.conf
如下。
# Local git repository setup
# Git repository information
SetEnv GIT_PROJECT_ROOT C:/Repositories
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAliasMatch \
"(?x)^/(.*/(HEAD | info/refs | objects/(info/[^/]+ | [0-9a-f]{2}/[0-9a-f]{38} | pack/pack-[0-9a-f]{40}.(pack|idx)) | git-(upload|receive)-pack))$" \
"C:/Program Files/git/libexec/git-core/git-http-backend.exe/$1"
# Allow cloning of repository without authentication
<Directory />
Require all granted
</Directory>
# Authentication
<LocationMatch "^/.*/git-receive-pack$">
Options +ExecCGI
AuthType Basic
AuthName "Git Login"
AuthUserFile "C:/wamp/bin/apache/apache2.4.9/passwords/git_passwords"
Require user alec
</LocationMatch>
另外,我在 SuperUser 和 StackOverflow 上都看到过类似的问题。如果有人能告诉我哪个网站更适合,那就太好了。
编辑
检查 apache 错误日志发现此错误
AH01215: Service not enabled: 'receive-pack'
新问题的解决方案
添加后SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
我可以推送到 repo 但从未要求我输入密码...
答案1
终于让一切正常了(虽然我不太清楚如何做到)。我的httpd.conf
文件最后的变化如下:
# Local git repository setup
# Git repository information
SetEnv GIT_PROJECT_ROOT C:/Repositories
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
ScriptAliasMatch \
"(?x)^/(.*/(HEAD | info/refs | objects/(info/[^/]+ | [0-9a-f]{2}/[0-9a-f]{38} | pack/pack-[0-9a-f]{40}.(pack|idx)) | git-(upload|receive)-pack))$" \
"C:/Program Files/git/libexec/git-core/git-http-backend.exe/$1"
# Allow cloning of repository without authentication
<Directory />
Require all granted
</Directory>
# Authentication
<LocationMatch "^/.*/git-receive-pack$">
Options +ExecCGI
AuthType Basic
AuthName "Git Login"
AuthUserFile "C:/wamp/bin/apache/apache2.4.9/passwords/git_passwords"
Require user alec
</LocationMatch>
<LocationMatch "^/.*/git-upload-pack$">
Options +ExecCGI
AuthType Basic
AuthName "Git Login"
AuthUserFile "C:/wamp/bin/apache/apache2.4.9/passwords/git_passwords"
Require user alec
</LocationMatch>
关键的一句台词似乎是SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
答案2
您有 的位置匹配,git-receive-pack
但 的位置不匹配git-upload-pack
。LocationMatch
对git-upload-pack
也执行相同的阻止操作。