如何通过http设置git? [英] How to set up git over http?

查看:52
本文介绍了如何通过http设置git?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用 git-over-http(智能 http)设置一个 git 服务器,但是网上可用的资源一团糟,混入其他 apache 配置,缺少细节或不够明确.

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.

推荐答案

首先有必要了解 git-over-http 有两个组件:git 和 apache.这两者通过一个名为 git-http-backend 的脚本连接起来.挑战在于配置这两个组件之间的接口,让对git的http请求由apache转发.

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.

  1. 首先使用发行版的包管理器安装 git 和 apache2.

  1. Start out by installing git and apache2 using the package manager of your distribution.

添加apache需要的模块来启用git-over-http.它们是 cgi、alias 和 env

Add the modules needed by apache to enable git-over-http. These are cgi, alias and env

$ a2enmod cgi alias env

  1. 将以下内容复制到/etc/apache2/httpd.conf(不删除它包含的任何其他内容)
  1. 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>

  1. 现在将出现的 2 个 /data/git 替换为您在服务器上的 git 存储库的父目录(如果您还没有任何存储库,请不要担心,只需使用该目录您打算放置它/它们的位置)
  1. 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)

同时将 /usr/lib/git/git-http-backend 替换为系统上 git-http-backend 的位置,可以使用 $ find/-name 找到git-http-backend

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

可能是在您的系统上 REDIRECT_REMOTE_USER 实际上覆盖了有效的 REMOTE_USER.如果此设置在完成后不起作用,请尝试删除该行.

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.

根据 this 来源,可能需要替换目录标记由 Require all allowed for apache 2.4 及以上.

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.

  1. 重启apache服务器:$ apache2ctl -k graceful

现在apache服务器已经设置好了,但我们还没有完成,设置repos的一些重要部分会影响这个设置是否有效.

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.

  1. 设置存储库:

$ 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

这里重要的是要了解最后一行将 repo 的所有者更改为 apache2 用户.此用户可能与您的系统不同.要查找 apache 用户,请执行 $ ps aux |egrep '(apache|httpd)'.然后要查找用户的组名,执行$ id user-name.在我的系统上,用户是 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.

  1. 使用存储库

为了使用 repo,您​​需要知道 url.对于此设置,网址为 http://server.domain/myrepo.git

In order to use the repo, you need to know the url. For this setup the url is http://server.domain/myrepo.git

注意:https 将不起作用.

Note: https will not work.

从客户端访问 repo 时,您只需将其添加为远程:

When accessing the repo from a client, you just add it as a remote:

$ git remote add origin http://server.domain/myrepo.git

然后你可以像任何其他 git repo 一样与它交互.

Then you can interact with it like any other git repo.

这篇关于如何通过http设置git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆