【发布时间】:2015-01-05 04:22:08
【问题描述】:
我一直在我的私人服务器上运行 SVN 存储库。我有几个项目要维护,所有项目都使用标准配置模式进行维护,该模式后来被用作 Apache macro。基本上我的结构很简单
-
https://svn.example.org
- /svnroot
- /repo1
- /repo2
- /viewvc
- /repo1
- /repo2
- /svnroot
映射于
- /home/me/srv/svn/repos
- /repo1
- /repo2
有多个宏,因为每个存储库都有自己的身份验证方案(公共读取、经过身份验证的提交或完全私有)
现在我想去 Git
即使我找到了一些使用 Apache 和 Git 的配置指令,我也没有正确理解它们。以下是我的问题:
我希望我的虚拟主机 (https://git.example.com) 托管多个 Git 存储库,所有这些都可以通过 shell 轻松配置(例如,添加 mod_macro 的 Use 指令并通过 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 协议是如何工作的,我如何独立于其他存储库来保护每个存储库?
【问题讨论】:
-
那个配置是 gitweb 配置。它允许我以一种奇特的方式显示 Git 存储库,而不是推送。对于推送,我应该研究 WebDAV 或 Smart HTTP (git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP)