如何设置git的通过http? [英] How to set up git over http?
问题描述
我需要设置用git-过HTTP(HTTP聪明),但资源可在网上Git服务器是一个烂摊子,在其他apache的配置,缺少细节混合或不是明确的不足。
我回答这个问题我根据我发现缺乏可用的资源。
首先,它是必要的了解,有2组件混帐过HTTP:Git和Apache的。这两个都通过与GIT-HTTP-后端的名称的脚本相连。面临的挑战是配置这两个组件之间的接口,以便http请求与git由阿帕奇转发
请注意:安全是本指南的范围之内。
-
通过使用分布的包管理器安装Git和Apache2的开始了。
-
添加阿帕奇需要启用混帐过HTTP模块。这些都是CGI,别名和env
$ a2enmod CGI别名ENV
-
复制以下到/etc/apache2/httpd.conf(不删除任何其他包含)
<虚拟主机*:80>
SETENV GIT_PROJECT_ROOT /数据/混帐
SETENV GIT_HTTP_EXPORT_ALL
SETENV REMOTE_USER = $ REDIRECT_REMOTE_USER
ScriptAliasMatch \\
(?X)。^ /(* /(HEAD | \\
信息/裁判| \\
对象/(信息/ [^ /] + | \\
[0-9A-F] {2} / [0-9A-F] {38} | \\
包/封装[0-9A-F] {40} \\。(包| IDX))| \\
git-(上传|接收)-pack))$\\
/ usr / lib目录/ git的/的git-HTTP后端/ $ 1
别名/ git的/数据/混帐
<目录/ usr / lib目录/混帐>
选项+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
设置AllowOverride无
为了允许,拒绝
所有允许
< /目录>
< /虚拟主机> -
现在更换2次出现/数据/混帐与你的git回购的服务器(父目录,如果你没有任何回购协议然而,在您打算只使用目录不用担心把它/他们)
另外替换 / usr / lib目录/ git的/的git-HTTP后端用git-HTTP-后端系统上的位置,可以使用找到
$找到/ -name的git-HTTP后端
这可能是因为在你的系统REDIRECT_REMOTE_USER实际上覆盖的有效REMOTE_USER。如果完成时这个设置不起作用,请尝试删除该行。
根据此的源,可能有必要通过<$替换目录标记中的最后两行C $ C>要求所有批准 为Apache 2.4 以上。
- 重新启动Apache服务器:
$ apache2ctl -k优美
现在Apache服务器设置,但我们还没有完成,还有一些会影响此设置是否管用设立回购的一些重要部分。
<醇开始=6> $的mkdir myrepo.git
$ CD myrepo.git
$ git的初始化--bare --shared
$ CP挂钩/后update.sample挂钩/后更新
$ git的更新,服务器信息
$ CHOWN -R wwwrun:WWW
这要明白,最后一行改变了回购的所有者apache2的用户是非常重要的。此用户可能是您的系统上有所不同。要找到apache用户,执行 $的ps aux | egrep的(阿帕奇| httpd的)
。然后查找用户的组名,执行 $ ID用户名
。在我的系统用户的 wwwrun 和组 WWW 。因此更换。
- 使用回购
为了使用回购协议,你需要知道的URL。对于此设置的URL为 HTTP://server.domain/myrepo.git
注意:HTTP的取值将无法正常工作
当从客户端访问回购,你只需将其添加为远程:
$ git的远程添加源HTTP://server.domain/myrepo.git
然后,你可以与它进行交互像任何其他混帐回购协议。
I need to set up a git server with git-over-http (smart http), but the resources available online are a mess, mixing in other apache configuration, missing details or not being explicit enough.
I am answering this question myself based on what I found lacking in the available resources.
First it is necessary to understand that there are 2 components to git-over-http: git and apache. These two are connected through a script with the name of git-http-backend. The challenge is to configure the interface between these two components, so that http requests to git are forwarded by apache.
Note: Security is outside the scope of this guide.
Start out by installing git and apache2 using the package manager of your distribution.
Add the modules needed by apache to enable git-over-http. These are cgi, alias and env
$ a2enmod cgi alias env
Copy the following into /etc/apache2/httpd.conf (without removing whatever else it contains)
<VirtualHost *:80> SetEnv GIT_PROJECT_ROOT /data/git SetEnv GIT_HTTP_EXPORT_ALL SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER ScriptAliasMatch \ "(?x)^/(.*/(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" Alias /git /data/git <Directory /usr/lib/git> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
Now replace the 2 occurrences of /data/git with the parent directory of your git repos on the server (don't worry if you don't have any repos yet, just use the directory where you intend to place it/them)
Also replace /usr/lib/git/git-http-backend with the location of git-http-backend on your system, which can be found using
$ find / -name git-http-backend
It may be that on your system REDIRECT_REMOTE_USER actually overwrites a valid REMOTE_USER. If this setup doesn't work when finished, try removing that line.
According to this source, it may be necessary to replace the last two lines within the Directory tag by Require all granted
for apache 2.4 and above.
- Restart the apache server:
$ apache2ctl -k graceful
Now the apache server is set up, but we're not done yet, there are some important parts of setting up the repos that will affect whether this setup works or not.
- Set up the repo:
$ mkdir myrepo.git
$ cd myrepo.git
$ git init --bare --shared
$ cp hooks/post-update.sample hooks/post-update
$ git update-server-info
$ chown -R wwwrun:www
Here it is important to understand that the last line changes the owner of the repo to the apache2 user. This user may be different on your system. To find the apache user, execute $ ps aux | egrep '(apache|httpd)'
. Then to find the group name of the user, execute $ id user-name
. On my system the user is wwwrun and the group www. Replace accordingly.
- Use the repo
In order to use the repo, you need to know the url. For this setup the url is http://server.domain/myrepo.git
Note: https will not work.
When accessing the repo from a client, you just add it as a remote:
$ git remote add origin http://server.domain/myrepo.git
Then you can interact with it like any other git repo.
这篇关于如何设置git的通过http?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!