我需要在 Windows 服务器上设置 Git 存储库。要求是:
我已经完成了标准的 Git 安装并将这些行添加到 Apache 的httpd.conf文件中:
SetEnv GIT_PROJECT_ROOT "D:/srv/git"
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ "C:/Program Files/Git/mingw64/libexec/git-core/git-http-backend/"
<Location "/git/testproject.git">
AuthType Basic
require group developers
AuthName "Git test project"
AuthUserFile D:/srv/gitauth/auth.txt
AuthGroupFile D:/srv/gitauth/groups.txt
</Location>
Run Code Online (Sandbox Code Playgroud)
"C:/Program Files/Git/mingw64/libexec/git-core/git-http-backend/"是我git-http-backend在 Windows 上找到可执行文件的地方。auth.txt是一个文件,htpasswd其中包含我的用户的用户名/密码,并groups.txt包含一行定义我的用户在名为developers.
为了测试,我在D:/srv/git/testproject.git.
在我的客户端计算机上,我尝试克隆此存储库并收到此错误:
git clone https://[serverurl]/git/testproject.git
Cloning into 'testproject'...
fatal: unable to access 'https://[serverurl]/git/testproject.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)
Apache 的 error.log 有这个错误信息:
[Wed Aug 23 18:39:10 2017] [error] [client 192.168.130.80] client denied by server configuration: C:/Program Files/Git/mingw64/libexec/git-core/git-http-backend
Run Code Online (Sandbox Code Playgroud)
我没有找到使这项工作的方法。不幸的是,我对 Apache 也不是很熟悉。
这个配置正确吗?我什至不确定SetEnvandScriptAlias命令是否适用,httpd.conf或者它们是否应该放在其他地方。我已经阅读了各种教程和博客文章,其中大多数建议我的 Apache 安装中不存在的不同地方(也许 Windows 环境不同......?)。
任何帮助将不胜感激!
经过几个小时的研究和测试,我终于让它运行起来并设法设置它以满足我的要求。
这是我必须添加到 Apache 的配置中才能使其工作的内容:
# 1. allow access to CGI directory, where git-http-backend.exe is located
<Directory "C:/Progra~1/Git/mingw64/libexec/git-core/">
Options +ExecCGI
Allow From All
</Directory>
# 2. Define where GIT projects are located and create /git/ script alias
SetEnv GIT_PROJECT_ROOT "D:/srv/git"
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ "C:/Progra~1/Git/mingw64/libexec/git-core/git-http-backend.exe/"
# 3. Restricting access to /git/ root, otherwise not yet defined projects could be read
# without restriction.
<Location "/git/">
AuthType Basic
AuthName "git"
AuthUserFile D:/srv/auth_files/htpasswd.txt
Require all denied
</Location>
# 4. For every project a section like this must be created in order to allow access to it.
<Location "/git/testproject.git/">
AuthType Basic
AuthName "git test repository"
AuthUserFile D:/srv/auth_files/htpasswd.txt
AuthGroupFile D:/srv/auth_files/git_groups.txt
Require group developers
</Location>
<Location "/git/other_project.git/">
AuthType Basic
AuthName "git test repository"
AuthUserFile D:/srv/auth_files/htpasswd.txt
AuthGroupFile D:/srv/auth_files/git_groups.txt
Require group developers managers
Require user sky
AuthzGroupFileAuthoritative Off
</Location>
Run Code Online (Sandbox Code Playgroud)
other_project.git允许两个组和一个用户访问。Apache 2.2 有AuthzGroupFileAuthoritative Off设置,使其正常工作。如果没有这个,只有开发人员或管理员组中的用户天空才能访问。在 Apache 2.4 中,这可以通过<RequireAny>块以更好的方式完成。git clone https://[serverurl]/git/testproject.git