我一直在私有服务器上运行SVN存储库。我有几个项目要维护,所有项目都使用标准配置模式维护,这些模式后来被用作Apache macro
。基本上我的结构很简单
映射到
有多个宏,因为每个存储库都有自己的身份验证方案(公共读取,已验证提交或完全私有)
即使我发现了一些使用Apache和Git的配置指令,我也无法正确理解它们。以下是我的问题:
我希望我的虚拟主机(https://git.example.com
)托管多个Git存储库,所有存储库都可以从shell轻松配置(例如,添加mod_macro
的Use
指令并git init
通过SSH运行)。每个人都有自己的许可系统,例如根据.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 [email protected]
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"
根据我的理解,上面的正则表达式匹配绝对路径,例如
/git/sdf/HEAD
/git/blablabla/blabla/objects/info/sdfs
/git/daf/git-receive-pack
好的,/git/
如果不进行更改,看来我所有的项目都将放在下面,是正确的吗?
但是然后,由于我目前不知道HTTP上的Git的工作方式,我如何独立地保护每个存储库的安全?
挖书可能会提供答案。这是我尝试之前的候选答案。
基本上,上述全局配置告诉所有以给定模式(例如git-receive-pack
)结尾的内容都发送到Git CGI。好的。
但是,使用适当的LocationMatch
,Alias
并<Directory>
指示应该工作。这是草稿:
Alias
将文件系统目录映射到某个位置<Directory>
进行设置.htaccess
。SVN用于HTTP verbs
区分读/写操作,Gitgit-receive-pack
用于写操作。该书建议使用LocationMatch
指令Macro
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句