1、编译安装fcgiwrap
git clone git://github.com/gnosek/fcgiwrap.git cd fcgiwrap autoreconf -i ./configure make make install
2、配置fcgiwrap开机脚本
vim /etc/init.d/fcgiwrap
#! /bin/sh # chkconfig: 2345 55 25 DESC="fcgiwrap daemon" DEAMON=/usr/bin/spawn-fcgi PIDFILE=/var/run/spawn-fcgi.pid FCGI_SOCKET=/var/run/fcgiwrap.socket FCGI_PROGRAM=/usr/local/sbin/fcgiwrap FCGI_USER=www FCGI_GROUP=www FCGI_EXTRA_OPTIONS="-M 0770" OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P $PIDFILE -- $FCGI_PROGRAM" do_start() { $DEAMON $OPTIONS || echo -n "$DESC already running" } do_stop() { kill -INT `cat $PIDFILE` || echo -n "$DESC not running" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 3 ;; esac exit 0
增加执行权限并开启
chmod +x fcgiwrap chkconfig fcgiwrap on
添加git的fastcgi配置
vim /path/to/Nginx/conf/fastcgi_params_git
fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE Nginx/$Nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param REMOTE_USER $remote_user; # required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;
添加git server的Nginx配置
server { listen 80; server_name mydevserver; access_log /var/log/Nginx/dev.access.log; error_log /var/log/Nginx/dev.error.log; location / { root /var/repos; } location ~ /git(/.*) { gzip off; root /usr/lib/git-core; fastcgi_pass unix:/var/run/fcgiwrap.socket; include fastcgi_params_git; 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 ""; fastcgi_param GIT_PROJECT_ROOT /var/repos; fastcgi_param PATH_INFO $1; #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } }
注意
git-http-backend
路径
附:
1、 Cannot access URL错误
error: Cannot access URL http://www.example.com/git/projects/example/,return code 22
仓库下:
git config http.receivepack true
- 安装编译
fcgiwrap
时
configure: error: FastCGI library is missing
安装fcgi-devel
yum install fcgi-devel -y