首页 > 代码库 > centos搭建git http服务器

centos搭建git http服务器

安装

yum -y install httpd git

创建仓库

mkdir /test && cd /test

git init --bare test.git

chown -R apache:apache /test/test.git 

vi /test/test.git/config

[http] 
receivepack = true

修改http.conf

vi /etc/httpd/conf/httpd.conf

# 设置git所管理的工程的存放目录
SetEnv GIT_PROJECT_ROOT /test
SetEnv GIT_HTTP_EXPORT_ALL

ScriptAlias /test/ /usr/libexec/git-core/git-http-backend/

# 对git库的各种请求,执行git-http-backend.cgi
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/libexec/git-core/git-http-backend/$1

ScriptAlias / /usr/share/gitweb/gitweb.cgi

#为git的http操作添加认证,认证信息存在git-auth文件中,关于此文件的配
#置将会在稍后讲解
<Location />
AuthType Basic
AuthName "Git Access"
AuthUserFile /var/www/git-auth
Require valid-user
AuthBasicProvider file
</Location>

创建连接

ln -s /test /var/www/test

生成密码

htpasswd -c git-auth user

启动

systemctl restart httpd

测试

git clone http://user:pwd@host/test/test.git

 

centos搭建git http服务器