转:基于http方式的git服务器搭建

来源:互联网 发布:五子棋最强软件 编辑:程序博客网 时间:2024/05/22 00:06

1.安装git

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install git git-core  

2.配置git的http代理

①安装apache

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install apache2 apache2-utils  

②激活下面的模块

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo a2enmod cgi alias env rewrite  

③修改apache的配置文件

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo vi /etc/apache2/sites-enabled/000-default.conf  

之后往里面加入如下内容

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. SetEnv GIT_PROJECT_ROOT /var/www/html/git  
  2. SetEnv GIT_HTTP_EXPORT_ALL  
  3. ScriptAlias /git/ /usr/lib/git-core/git-http-backend/  
  4.    
  5. RewriteEngine On  
  6. RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]  
  7. RewriteCond %{REQUEST_URI} /git-receive-pack$  
  8. RewriteRule ^/git/ - [E=AUTHREQUIRED]  
  9.    
  10. <Files "git-http-backend">  
  11.     AuthType Basic  
  12.     AuthName "Git Access"  
  13.     AuthUserFile /var/www/html/.htpasswd(此处位置与下文创建用户验证一致)  
  14.     Require valid-user  
  15.     Order deny,allow  
  16.     Deny from env=AUTHREQUIRED  
  17.     Satisfy any  
  18. </Files>  

④创建用户验证

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo htpasswd -c /var/www/html/.htpasswd zwj(用户名)  
  2. 首次添加的时候要加-c选项,之后添加的时候去掉-c选项,不然会将原有的账户删除  


(1)进入部署web项目的目录,如/var/www/html/


(2)新建git文件夹

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo mkdir git  
  2. cd git  

(3)初始化git仓库

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo git init --bare zwj.git (最后面的名字随意取,为了命名规范,一般使用.git结尾)  


4.修改/var/www/目录的所属者和所有者权限

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. chown -R www-data: www-data /var/www/  

5.启动apache

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. sudo service apache2 restart  

根据以上步骤配置好之后,就可以使用http的方式去同步git项目,路径为

http://ip/git/zwj.git(最后的名字自行替换成你新建git仓库时候的名字)

0 0
原创粉丝点击