1. 安装git, gitweb, spawn-fcgi
yum install -y git gitweb spawn-fcgi fcgi-devel fcgi
2. 安装fcgiwrap
http://my.oschina.net/Kilar/blog/543081
3. 编辑/etc/gitweb.conf
$projectroot = "/data/git/repo" $git_temp = "/tmp"; $home_text = "indextext.html"; #$projects_list = "/home/git/projects.list"; @stylesheets = ("static/gitweb.css"); $javascript = "static/gitweb.js"; $favicon = "static/eab-favicon.png"; @diff_opts = (); $feature{pathinfo}{default} = [1];
4. 修改/etc/sysconfig/spawn-fcgi
FCGI_SOCKET=/var/run/fcgiwrap.socket FCGI_PROGRAM=/usr/local/bin/fcgiwrap FCGI_USER=nginx FCGI_GROUP=nginx FCGI_EXTRA_OPTIONS="-M 0700" OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"
5. 添加nginx的git配置
mkdir -p /usr/local/nginx/conf/vhost
vim /usr/local/nginx/conf/vhost
server { listen 80; server_name git.ee; # 用户认证,passwd使用htpasswd生成,和apache一样,htpasswd可以从soft.vpser.net/lnmp/ext/htpasswd.sh获取 error_log /data/user/log/nginx/git.error.log; access_log /data/user/log/nginx/git.access.log; client_max_body_size 4000m; client_body_buffer_size 8m; auth_basic "Git Authorize"; auth_basic_user_file /home/data/passwd; # 访问地址为http://your_hsotname/xxxx.git location ~ (/.*) { # disalbe gzip gzip off; # fastcgi sockt fastcgi_pass unix:/var/run/fcgiwrap.socket; # fastcgi parameters include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend; fastcgi_param DOCUMENT_ROOT /usr/libexec/git-core/; fastcgi_param SCRIPT_NAME git-http-backend; fastcgi_param GIT_HTTP_EXPORT_ALL ""; # git的工作目录 fastcgi_param GIT_PROJECT_ROOT /data/git/repo; fastcgi_param PATH_INFO $1; fastcgi_param REMOTE_USER $remote_user; } }
6. git push拒绝时 ([remote rejected] master )
这是由于git默认拒绝了push操作,需要进行设置,修改.git/config文件后面添加如下代码:
[receive]
denyCurrentBranch = ignore
无法查看push后的git中文件的原因与解决方法
在初始化远程仓库时最好使用 git --bare init 而不要使用:git init
如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上, 也即在远程仓库的目录下对应的文件还是之前的内容。
解决方法:
必须得使用命令 git reset --hard 才能看到push后的内容.
参考
http://www.wy182000.com/2014/08/22/centos%E4%B8%8B%E4%BD%BF%E7%94%A8nginx%E6%90%AD%E5%BB%BAgit-http%E6%9C%8D%E5%8A%A1%EF%BC%8C%E6%94%AF%E6%8C%81gitlist%E8%AE%BF%E9%97%AE/
http://blog.csdn.net/yuanchao99/article/details/39052937
http://www.cnblogs.com/shmmah/p/5016735.html