Ubuntu、Git(git-http-backend)和 Apache

Ubuntu、Git(git-http-backend)和 Apache

我正在尝试设置一个基于 git 及其 git-http-backend 和 apache 的存储库服务器。我的问题是什么?我可以完美地克隆,但当我尝试推送时,我遇到了障碍

$ git push origin master
* Couldn't find host git.local in the .netrc file; using defaults
* About to connect() to git.local port 80 (#0)
*   Trying 127.0.0.1... * connected
* Connected to git.local (127.0.0.1) port 80 (#0)
> GET /new/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.1
Host: git.local
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Date: Tue, 23 Nov 2010 16:21:51 GMT
< Server: Apache/2.2.16 (Ubuntu)
< WWW-Authenticate: Basic realm="Private Git Access"
< Vary: Accept-Encoding
< Content-Length: 476
< Content-Type: text/html; charset=iso-8859-1
< 
* Ignoring the response-body
* Connection #0 to host git.local left intact
* Issue another request to this URL: 'http://shoaibi:[email protected]/new/info/refs?service=git-receive-pack'
* Couldn't find host git.local in the .netrc file; using defaults
* Re-using existing connection! (#0) with host git.local
* Connected to git.local (127.0.0.1) port 80 (#0)
* Server auth using Basic with user 'shoaibi'
> GET /new/info/refs?service=git-receive-pack HTTP/1.1
Authorization: Basic c2hvYWliaTpzaG9haWJp
User-Agent: git/1.7.1
Host: git.local
Accept: */*
Pragma: no-cache

< HTTP/1.1 200 OK
< Date: Tue, 23 Nov 2010 16:21:51 GMT
< Server: Apache/2.2.16 (Ubuntu)
< Last-Modified: Tue, 23 Nov 2010 15:30:17 GMT
< ETag: "8853-0-495ba0cca2f10"
< Accept-Ranges: bytes
< Content-Length: 0
< Content-Type: text/plain
< 
* Connection #0 to host git.local left intact
* Couldn't find host git.local in the .netrc file; using defaults
* Re-using existing connection! (#0) with host git.local
* Connected to git.local (127.0.0.1) port 80 (#0)
* Server auth using Basic with user 'shoaibi'
> GET /new/HEAD HTTP/1.1
Authorization: Basic c2hvYWliaTpzaG9haWJp
User-Agent: git/1.7.1
Host: git.local
Accept: */*
Pragma: no-cache

< HTTP/1.1 200 OK
< Date: Tue, 23 Nov 2010 16:21:51 GMT
< Server: Apache/2.2.16 (Ubuntu)
< Last-Modified: Tue, 23 Nov 2010 12:05:07 GMT
< ETag: "88b7-17-495b72f0814f0"
< Accept-Ranges: bytes
< Content-Length: 23
< Content-Type: text/plain
< 
* Expire cleared
* Connection #0 to host git.local left intact
* Couldn't find host git.local in the .netrc file; using defaults
* About to connect() to git.local port 80 (#0)
*   Trying 127.0.0.1... * connected
* Connected to git.local (127.0.0.1) port 80 (#0)
> PROPFIND /new/ HTTP/1.1
User-Agent: git/1.7.1
Host: git.local
Accept: */*
Depth: 0
Content-Type: text/xml
Content-Length: 167
Expect: 100-continue

< HTTP/1.1 401 Authorization Required
< Date: Tue, 23 Nov 2010 16:21:51 GMT
< Server: Apache/2.2.16 (Ubuntu)
< WWW-Authenticate: Basic realm="Private Git Access"
< Vary: Accept-Encoding
< Content-Length: 476
< Content-Type: text/html; charset=iso-8859-1
< 
* Expire cleared
* Closing connection #0
* Issue another request to this URL: 'http://shoaibi:[email protected]/new/'
* Couldn't find host git.local in the .netrc file; using defaults
* About to connect() to git.local port 80 (#0)
*   Trying 127.0.0.1... * connected
* Connected to git.local (127.0.0.1) port 80 (#0)
* Server auth using Basic with user 'shoaibi'
> PROPFIND /new/ HTTP/1.1
Authorization: Basic c2hvYWliaTpzaG9haWJp
User-Agent: git/1.7.1
Host: git.local
Accept: */*
Depth: 0
Content-Type: text/xml
Content-Length: 167
Expect: 100-continue

< HTTP/1.1 100 Continue
* The requested URL returned error: 405
* Expire cleared
* Closing connection #0
error: Cannot access URL http://shoaibi:[email protected]/new/, return code 22
fatal: git-http-push failed

Apache 的日志显示:

127.0.0.1 - - [23/Nov/2010:21:21:51 +0500] "GET /new/info/refs?service=git-receive-pack HTTP/1.1" 401 725
127.0.0.1 - shoaibi [23/Nov/2010:21:21:51 +0500] "GET /new/info/refs?service=git-receive-pack HTTP/1.1" 200 231
127.0.0.1 - shoaibi [23/Nov/2010:21:21:51 +0500] "GET /new/HEAD HTTP/1.1" 200 256
127.0.0.1 - - [23/Nov/2010:21:21:51 +0500] "PROPFIND /new/ HTTP/1.1" 401 725
127.0.0.1 - shoaibi [23/Nov/2010:21:21:51 +0500] "PROPFIND /new/ HTTP/1.1" 405 553

git-http-backend 需要启用 cgi、别名和 env 模块,这些已经启用,在阅读了谷歌上的一些结果后,我甚至尝试启用和禁用 dav 相关模块。Apache 启用的模块:

 $apache2ctl -M
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cache_module (shared)
 cgi_module (shared)
 dav_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mem_cache_module (shared)
 mime_module (shared)
 security2_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 proxy_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 ssl_module (shared)
 status_module (shared)
 unique_id_module (shared)
 userdir_module (shared)
Syntax OK

Apache 的 Vhost:

<VirtualHost *:80>
        ServerName www.git.local
        ServerAlias git.local
        ServerAdmin [email protected]
        DocumentRoot /var/www/git/

        SetEnv GIT_PROJECT_ROOT /var/www/git
        SetEnv GIT_HTTP_EXPORT_ALL
        ScriptAlias /git/ /usr/lib/git-core/git-http-backend
        <Directory />
            Options +ExecCGI
            Allow From All
        </Directory>


        <Location />
                AuthType Basic
                AuthName "Private Git Access"
                Require group committers
                AuthUserFile /var/www/git/.htpasswd
                AuthGroupFile /var/www/git/.htgroup
        </Location>

        ErrorLog /var/log/apache2/git-error_log
        CustomLog /var/log/apache2/git-access_log common


</VirtualHost>

密码:

$ cat .htpasswd
shoaibi:HSt/9CzkstIUM

ht群组:

$ cat .htgroup
committers: shoaibi

目录结构:

$ ls -al
total 28
drwxrwxr-x  4 www-data shoaibi 4096 2010-11-23 17:05 .
drwxrwxr-x 17 www-data shoaibi 4096 2010-11-23 11:46 ..
-rwxrwxr-x  1 www-data shoaibi   20 2010-11-23 16:51 .htgroup
-rwxrwxr-x  1 www-data shoaibi   22 2010-11-23 16:50 .htpasswd
-rwxrwxr-x  1 www-data shoaibi    9 2010-11-23 15:46 index.html
drwxrwxr-x  7 www-data shoaibi 4096 2010-11-23 11:53 myrepo.git
drwxrwxr-x  7 www-data shoaibi 4096 2010-11-23 17:05 new


$ ls -al new
total 40
drwxrwxr-x 7 www-data shoaibi 4096 2010-11-23 17:05 .
drwxrwxr-x 4 www-data shoaibi 4096 2010-11-23 17:05 ..
drwxrwxr-x 2 www-data shoaibi 4096 2010-11-23 17:05 branches
-rwxrwxr-x 1 www-data shoaibi   66 2010-11-23 17:05 config
-rwxrwxr-x 1 www-data shoaibi   73 2010-11-23 17:05 description
-rwxrwxr-x 1 www-data shoaibi   23 2010-11-23 17:05 HEAD
drwxrwxr-x 2 www-data shoaibi 4096 2010-11-23 17:05 hooks
drwxrwxr-x 2 www-data shoaibi 4096 2010-11-23 20:30 info
drwxrwxr-x 4 www-data shoaibi 4096 2010-11-23 17:05 objects
drwxrwxr-x 4 www-data shoaibi 4096 2010-11-23 17:05 refs


 $ ls -al myrepo.git
total 40
drwxrwxr-x 7 www-data shoaibi 4096 2010-11-23 11:53 .
drwxrwxr-x 4 www-data shoaibi 4096 2010-11-23 17:05 ..
drwxrwxr-x 2 www-data shoaibi 4096 2010-11-23 11:53 branches
-rwxrwxr-x 1 www-data shoaibi   66 2010-11-23 11:53 config
-rwxrwxr-x 1 www-data shoaibi   73 2010-11-23 11:53 description
-rwxrwxr-x 1 www-data shoaibi   23 2010-11-23 11:53 HEAD
drwxrwxr-x 2 www-data shoaibi 4096 2010-11-23 11:53 hooks
drwxrwxr-x 2 www-data shoaibi 4096 2010-11-23 16:20 info
drwxrwxr-x 4 www-data shoaibi 4096 2010-11-23 11:53 objects
drwxrwxr-x 4 www-data shoaibi 4096 2010-11-23 11:53 refs

答案1

查看你的 VHost 文件,我不确定 git 后端是否正在启动。

ScriptAlias /git/ /usr/lib/git-core/git-http-backend

这实际上不会做任何事情,除非你处于这样的页面http://git.local/git/somethingelse- 由于你的 DocumentRoot 是 /var/www/git/ ,而你的存储库是 /var/www/git/ 下的文件夹,因此 ScriptAlias 行毫无用处,因为你永远不会导航http://git.local/git/

答案2

你 入住 了git config http.receivepack true/var/www/git/new?

相关内容