首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于http的Git存储库,Apache2配置不起作用

问基于http的Git存储库,Apache2配置不起作用
EN

Stack Overflow用户
提问于 2020-12-27 14:08:02
回答 1查看 223关注 0票数 0

我的目标是通过HTTP/HTTPS在git cloneweb服务器2.4.29上实现对git裸存储库的匿名读访问(git pull/ git pull)和身份验证的写访问(git push)。

我尝试文档化的配置(https://git-scm.com/docs/git-http-backend):

代码语言:javascript
复制
SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

..。在这两种变体中。

变式1)与模块mod_rewrite

代码语言:javascript
复制
RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]

<LocationMatch "^/git/">
    Order Deny,Allow
    Deny from env=AUTHREQUIRED
    AuthType Basic
    AuthName "Git Access"
    AuthBasicProvider ldap
    AuthLDAPURL ldap://ldapserver:386
    Require user test
    Satisfy Any
</LocationMatch>

变式2:没有模块mod_rewrite

代码语言:javascript
复制
<LocationMatch "^/git/.*/git-receive-pack$">
    AuthType Basic
    AuthName "Git Access"
    AuthBasicProvider ldap
    AuthLDAPURL ldap://ldapserver:386
    Require user test
</LocationMatch>

<LocationMatch "^/git/">
    Require all granted
    Allow from all
</LocationMatch>

我在服务器端使用debian包apache2 (2.4.29-1 ubuntu4.14),在客户端使用git2.29.2来测试配置。

两种变体都不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-27 14:08:02

这个问题是由不完整的文档https://git-scm.com/docs/git-http-backend引起的。

对于mod_rewrite**)**变体1(使用模块),需要启用重写引擎。添加RewriteEngine On解决了这个问题。使用正确的LogLevel语句(在下面的示例中注释掉),您可以在apache2日志文件中观察正确的行为。

代码语言:javascript
复制
RewriteEngine On
#LogLevel alert rewrite:trace6

SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

对于rewrite_mod**)**变体2(没有模块 LocationMatch ),在我的示例中LocationMatch将不匹配,因为git pull是使用查询字符串完成的:

代码语言:javascript
复制
GET /git/repo.git/info/refs?service=git-receive-pack

描述的LocationMatch无法检查请求的查询字符串。

见http://httpd.apache.org/docs/2.0/en/mod/core.html#location ..。

不包括任何方案、主机名、端口或查询字符串。

一个解决方案是在<If>...</If><Else>...</Else>中添加LocationMatch (也请参阅2019594)。使用CustomLog语句,如果LocationMatch按需要工作,就可以签入日志文件(参见https://serverfault.com/questions/718234/how-to-check-if-locationmatch-regex-is-working)。

代码语言:javascript
复制
CustomLog ${APACHE_LOG_DIR}/location.log "%h %l %u %t \"%r\" %>s %b what:%{INDICATOR_VAR}e"

<LocationMatch "^/git/">
    <If "%{QUERY_STRING} =~ /service=git-receive-pack/">
         SetEnv INDICATOR_VAR "git push"
         AuthType Basic
         AuthName "Git Access"
         AuthBasicProvider ldap
         AuthLDAPURL ldap://ldapserver:386
         Require user test
         Allow from all
    </If>
    <Else>
         SetEnv INDICATOR_VAR "git pull"
         Require all granted
         Allow from all
    </Else>
</LocationMatch>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65466618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档