kernelsky 发表于 2018-1-16 08:33:11

Git Http Server

#http://www.wretch.cc/blog/michaeloil/22286355  
#http://blog.longwin.com.tw/2009/05/build-git-env-over-http-2009/
  

  
#安装软件
  
sudo apt-get install git-core
  
sudo apt-get install apache2
  
#启用相应模块
  
sudo a2enmod dav_fs
  
#sudo a2enmod dav
  

  
#设置apache2
  
sudo htpasswd -c /etc/apache2/dav_git.passwd dav
  
>New password: 123
  
>Re-type new password: 123
  
>Adding password for user dav
  

  
sudo vim /etc/apache2/sites-available/git.conf
  
<VirtualHost *:80>
  
ServerAdmin user@example.com
  
DocumentRoot /var/cache/git
  
ServerName git.example.com
  
ErrorLog /var/log/apache2/git-error.log
  
CustomLog /var/log/apache2/git-access.log combined  
  
SetEnv GIT_PROJECT_ROOT /var/cache/git/
  
SetEnv GIT_HTTP_EXPORT_ALL
  
ScriptAliasMatch ^(/.+?\.git.*)$ /usr/lib/git-core/git-http-backend$1
  

  
<Location "/test.git/">
  
DAV on
  
AuthType Basic
  
AuthName "Git"
  
AuthUserFile /etc/apache2/dav_git.passwd
  
Require valid-user
  
</Location>
  
</VirtualHost>
  

  
#删除原来监听80端口的默认文件
  
sudo rm /etc/apache2/sites-enabled/000-default
  
#启用新的git配置
  
sudo ln -s /etc/apache2/sites-available/git.conf /etc/apache2/sites-enabled/git.conf
  
#重启
  
sudo /etc/init.d/apache2 restart
  

  

  
#设置git
  
sudo mkdir -p /var/cache/git/test.git
  
cd /var/cache/git/test.git
  
sudo git --bare init
  
sudo git update-server-info
  
sudo cp hooks/post-update.sample hooks/post-update
  
sudo chown www-data:www-data -R .
  

  

  
goodspeed@bogon:/var/cache/git$ sudo mkdir test.git
  
goodspeed@bogon:/var/cache/git$ cd test.git/
  
goodspeed@bogon:/var/cache/git/test.git$ sudo git --bare init
  
Initialized empty Git repository in /var/cache/git/test.git/
  
goodspeed@bogon:/var/cache/git/test.git$ sudo chown www-data:www-data -R .
  
goodspeed@bogon:/var/cache/git/test.git$ sudo git update-server-info
  
goodspeed@bogon:/var/cache/git/test.git$ sudo cp hooks/post-update.sample hooks/post-update
  
goodspeed@bogon:/var/cache/git/test.git$ sudo chown www-data:www-data -R .
  
goodspeed@bogon:/var/cache/git/test.git$ ll
  

  

  
curl --netrc --location http://127.0.0.1/test.git/HEAD
  
curl --netrc --location -v http://127.0.0.1/test.git/HEAD
页: [1]
查看完整版本: Git Http Server