使用Apache 2.4设置git-http-backend [英] Setting Up git-http-backend with apache 2.4

查看:164
本文介绍了使用Apache 2.4设置git-http-backend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用git-http-backend和apache 2.4设置git服务器,我发现

Im trying to set up a git server using git-http-backend and apache 2.4 I found this question about the same thing which was helpful, but I'm still reaching a point where I'm stuck.

我已经在Ubuntu 16.04上安装了git和apache2,并使用添加了所需的模块

I've installed git and apache2 on Ubuntu 16.04 and added the needed modules using

sudo a2enmod cgi alias env

然后在/etc/apache2/apache2.conf中添加了以下代码段:

Then added the following snippet in /etc/apache2/apache2.conf :

<VirtualHost *:80>
    SetEnv GIT_PROJECT_ROOT /var/www/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-core/git-http-backend/$1"
    Alias /git /var/www/git
    <Directory /usr/lib/git-core>
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

请注意,我打算在/var/www/git上运行我的存储库并运行

Note that /var/www/git is where I intend my repos to go, and running

find / -name git-http-backend显示/usr/lib/git-core/git-http-backend

接下来,在/var/www/git/内部,我创建了一个目录myrepo.git并将其设置为:

Next, inside of /var/www/git/ I created a directory myrepo.git and set it up as such:

sudo git init --bare --shared
sudo cp hooks/post-update.sample hooks/post-update
sudo git update-server-info

接下来,我必须将目录的所有权更改为apache2所有者(告诉我).运行ps aux | egrep '(apache|httpd)'返回以下内容:

Next, I have to change the ownership of the directory to the apache2 owner (Im told). Running ps aux | egrep '(apache|httpd)' returns the following:

root 3087 0.0 0.4 73688  4928 ? Ss 02:37 0:00 /usr/sbin/apache2 -k start
www-data 3455 0.0 0.5 362836  5852 ? Sl 03:13 0:00 /usr/sbin/apache2 -k start
www-data 3456 0.0 0.5 362836  5852 ? Sl 03:13 0:00 /usr/sbin/apache2 -k start
git 3531 0.0 0.0 14512 932 pts/1 S+ 03:19 0:00 grep -E --color=auto (apache|httpd)

现在我不确定,因为看起来rootwww-data都在运行,但是我目前决定将所有权设置为www-data(也许应该是root?). www-data的组也是www-data(我认为)

Now I'm not sure, because it looks like both root and www-data are running something, but I have currently decided to set the ownership to www-data (maybe it should be root?). www-data's group is also www-data (I think)

$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)

所以我用它来设置所有权:

so I use that to set ownership:

sudo chown -R www-data:www-data .

我似乎还记得读过,整个路径必须属于apache用户,因此我只是出于很好的考虑而设置

I also seem to remember reading that the whole path has to belong to the apache user so just for good measure I set

sudo chown -R www-data:www-data /var/www

现在从本地计算机上,我正在尝试克隆myrepo:

Now from my localmachine I am trying to clone the myrepo:

git clone http://<ip-address>/myrepo.git

我得到了错误:

fatal: unable to access 'http://<ip-address>/myrepo.git/': The requested URL returned error: 503

有人能看到我在做什么吗?

Can anybody see what Im doing wrong?

推荐答案

Alias /git /var/www/git

这应该表示您的网址中应包含/git:

That should mean your urls should include /git in it:

git clone http://<ip-address>/git/myrepo.git

在此 查看全文

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