我需要在 Windows 服务器上设置 Git 存储库。要求是:
- Git 在带有 Apache 2.2 的 Windows 上运行(因为这个 Apache 已经存在并且已经用于服务 Subversion)
- 允许创建各种 Git 存储库
- 存储库不公开。必须能够定义每个项目的访问权限。有权访问存储库的用户始终拥有完全访问权限( pull 和推送)。
我已经完成了标准的 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>
"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
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
我没有找到实现此功能的方法。不幸的是,我对 Apache 也不是很熟悉。
这个配置是否正确?
我什至不确定 SetEnv
和 ScriptAlias
命令在 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>
一些注意事项
- 第 (1) 部分似乎只在 Windows 上是必需的。如果没有此指令,Apache 将不会将 git-http-backend.exe 文件作为 CGI 脚本执行。
- 第 (3) 部分是必要的,因为如果没有它,Apache 将允许访问以后未在配置中明确定义的每个项目。
- 第(4)部分项目
other_project.git
允许两个组和一个用户访问。 Apache 2.2 有AuthzGroupFileAuthoritative Off
设置,使它正常工作。如果没有这个,开发人员或经理只能访问组中的用户天空。在 Apache 2.4 中,这可以使用<RequireAny>
以更好的方式完成。阻止。 - 克隆这些存储库之一的示例:
git clone https://[serverurl]/git/testproject.git
关于git - 在 Windows 服务器上使用 Apache 配置 Git,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45846897/