閱讀本文前你必須預先裝好CentOS並且已經安裝和配置好Nginx了。
安裝centos6.5-centos7.0
cdfcgiwrap autoreconf -i Configure Make make install
$projectroot = "/home/git/repositories"; @git_base_url_list= ("git://192.168.0.101", "http://192.168.0.101:81"); $git_temp = "/tmp"; $home_text = "indextext.html"; @stylesheets = ("gitweb.css"); $javascript = "gitweb.js"; @diff_opts = (); $feature{pathinfo}{default} = [1]; $feature{'highlight'}{'default'} = [1];
# You must set some working options before the "spawn-fcgi" service will work. # If SOCKET points to a file, then this file is cleaned up by the init script. # # See spawn-fcgi(1) for all possible options. # # Example : #SOCKET=/var/run/php-fcgi.sock #OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"
# You must set some working options before the "spawn-fcgi" service will work. # If SOCKET points to a file, then this file is cleaned up by the init script. # # See spawn-fcgi(1) for all possible options. # # Example : #SOCKET=/var/run/php-fcgi.sock #OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi" FCGI_SOCKET=/var/run/fcgiwrap.socket FCGI_PROGRAM=/usr/local/sbin/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"
chkconfig --levels 2345 spawn-fcgi on /etc/init.d/spawn-fcgi start
useradd gitpasswd git su git #切換到git用戶 mkdir repositories #會在/home/git目錄下建立repositories目錄 #開始建立git的root repositories mkdir /home/git/.ssh cd /home/git/.sshssh-keygen -t rsa git gitosis-init < ~/.ssh/id_rsa.pub
su git cd repositories mkdir hello.git cd hello.git git --bare init sudo chmod 777 /home/git/repositories/hello.git –R
useradd ymk passwd ymk cd /home/ymk mkdir git_repo cd git_repo mkdir hello.git cd hello.git git init
touch readme #新建一個readme文本文件 vi readme #隨便在此文件中寫點什麼然後保存退出即可 git add . 代表把當前目錄內所有東西進行遠程推送 git commit -a -m “init helloworld“ #代表commit所有之前add過的東東,並且帶上commit時的注釋 git remote add origin [email protected]:/home/git/repositories/hello.git #建立遠程GIT連接 git push origin master #正式推送
server { error_log logs/git.error.log; access_log logs/git.access.log; listen 81; server_name 192.168.0.101; index gitweb.cgi; root /home/git; location ~ \.(cgi|pl).*$ { gzip off; fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_param SCRIPT_FILENAME /home/git/gitweb.cgi; fastcgi_param SCRIPT_NAME gitweb.cgi; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { root /home/git; } location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { root /home/git; fastcgi_param QUERY_STRING $query_string; fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend; fastcgi_param GIT_HTTP_EXPORT_ALL true; fastcgi_param GIT_PROJECT_ROOT /home/git/repositories; fastcgi_param PATH_INFO $uri; include fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; } try_files $uri @gitweb; location @gitweb { fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_param SCRIPT_FILENAME /var/www/git/gitweb.cgi; fastcgi_param PATH_INFO $uri; fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; include fastcgi_params; }
server { error_log logs/git.error.log; access_log logs/git.access.log; listen 81; server_name 192.168.0.101; index gitweb.cgi; root /home/git;
location ~ \.(cgi|pl).*$ { gzip off; fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_param SCRIPT_FILENAME /home/git/gitweb.cgi; fastcgi_param SCRIPT_NAME gitweb.cgi; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { root /home/git; }這兩段告訴了NG,凡是cgi的去哪裡找.cgi文件,一定注意不要漏了include fastcgi_params;這一句,你也可以去/usr/local/nginx下看看,是否有這個文件。
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { root /home/git; fastcgi_param QUERY_STRING $query_string; fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend; fastcgi_param GIT_HTTP_EXPORT_ALL true; fastcgi_param GIT_PROJECT_ROOT /home/git/repositories; fastcgi_param PATH_INFO $uri; include fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; } try_files $uri @gitweb; location @gitweb { fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_param SCRIPT_FILENAME /var/www/git/gitweb.cgi; fastcgi_param PATH_INFO $uri; fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; include fastcgi_params; }
su git cd /home/git/repositories/hello.git git config --file config http.receivepack true
cd /usr/local/nginx ./nginx –c /usr/local/nginx/nginx.conf