【问题标题】:Setting up private multiple public/private Git repositories with Apache and mod_macro使用 Apache 和 mod_macro 设置私有的多个公共/私有 Git 存储库
【发布时间】:2015-01-05 04:22:08
【问题描述】:

我一直在我的私人服务器上运行 SVN 存储库。我有几个项目要维护,所有项目都使用标准配置模式进行维护,该模式后来被用作 Apache macro。基本上我的结构很简单

映射于

  • /home/me/srv/svn/repos
    • /repo1
    • /repo2

有多个宏,因为每个存储库都有自己的身份验证方案(公共读取、经过身份验证的提交或完全私有)

现在我想去 Git

即使我找到了一些使用 Apache 和 Git 的配置指令,我也没有正确理解它们。以下是我的问题:


我希望我的虚拟主机 (https://git.example.com) 托管多个 Git 存储库,所有这些都可以通过 shell 轻松配置(例如,添加 mod_macroUse 指令并通过 SSH 运行 git init)。每个人都有自己的权限系统,例如根据.htpasswd。典型的存储库路径可以是 https://git.example.com/[projects-or-whatever]/myProject.git 映射到 /home/me/srv/git/repos/myProject 之类的地方

如何在 Apache 中做到这一点?


到目前为止很糟糕

我尝试构建一个如下所示的 Git 配置(尚未测试,因为它暂时不会做任何事情)

<VirtualHost *:443>
    ServerName git.example.com
    ServerAlias www.git.example.com
    ServerAdmin me@example.com
    AssignUserID me myself

    # Use HTTP Strict Transport Security to force client to use secure connections only
    Header always set Strict-Transport-Security "max-age=500000000"

    ErrorLog /path/to/error_log
    CustomLog /path/to/access_log "vhost_combined"

    DocumentRoot /srv/www/default

    SSLEngine on
    SSLOptions +StrictRequire
    #SSLPassPhraseDialog builtin
    SSLCertificateFile /path/to.crt
    SSLCertificateKeyFile /path/to.key
    SSLCertificateChainFile /path/to.ca-bundle
    SSLVerifyClient none
    SSLProxyEngine on

    #Used for system login instead of .htaccess
    AddExternalAuth pwauth /usr/bin/pwauth
    SetExternalAuthMethod pwauth pipe

    <IfModule mime.c>
        AddType application/x-x509-ca-cert      .crt
        AddType application/x-pkcs7-crl         .crl
    </IfModule>



    ScriptAliasMatch \
       "(?x)^/git/(.*/(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))$" \
       "/usr/lib/git/git-http-backend/$1"

    ScriptAlias /git /usr/share/gitweb/gitweb.cgi
    SetEnv GIT_PROJECT_ROOT /home/me/srv/git/repos/
    SetEnv GIT_HTTP_EXPORT_ALL


    #In this directory, specific repositories are configured
    Include "/home/hosting/vhosts.d/me/git/*.git.conf"

    <Directory "/home/me/srv/git/repos">
        Allow from all
        Options +ExecCGI
        AllowOverride All
    </Directory>


    <Directory "/usr/lib/git/">
        Options ExecCGI Indexes
        Order allow,deny
        Allow from all
    </Directory>

    AddHandler cgi-script cgi
    DirectoryIndex gitweb.cgi

    <Files gitweb.cgi>
        SetHandler cgi-script
    </Files>
</VirtualHost>

但是让我们专注于我现在无法理解的以下行

 ScriptAliasMatch \
       "(?x)^/git/(.*/(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))$" \
       "/usr/lib/git/git-http-backend/$1"

从我的understanding 来看,上面的正则表达式匹配绝对路径,例如

/git/sdf/HEAD
/git/blablabla/blabla/objects/info/sdfs
/git/daf/git-receive-pack

好的,如果我不更改它,看起来我所有的项目都将放在/git/ 下,对吗

但是,由于我目前不知道 Git over HTTP 协议是如何工作的,我如何独立于其他存储库来保护每个存储库

【问题讨论】:

标签: git apache


【解决方案1】:

挖掘the book 可能会提供答案。这是我尝试之前的候选答案。

基本上,上述全局配置告诉以给定模式(例如git-receive-pack)结尾的所有内容都被发送到 Git CGI。好的。

但是使用正确的LocationMatchAlias&lt;Directory&gt; 指令应该可以工作。这是草稿:

  • 使用Alias 将文件系统目录映射到某个位置
  • 如果需要,使用&lt;Directory&gt; 设置.htaccess。 SVN 使用HTTP verbs 区分读/写操作,Git 使用git-receive-pack 进行写操作。本书建议使用LocationMatch 指令
  • 将所有内容包装在 Macro

【讨论】:

    猜你喜欢
    • 2011-12-27
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    • 2016-10-18
    • 2019-08-30
    • 2022-12-19
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多