Installing cgit with nginx on CentOS 5.4
作者: 曲文庆 日期: 2014-05-15 18:06
Installing cgit with nginx on CentOS 5.4
Here is how to setup cgit to run on nginx.
pre-requisites
Before you start, make sure the following packages are installed on the system using your favorite package manager.
#### autoconf 2.69 http://ftp.gnu.org/gnu/autoconf/ wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz tar zxvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix=/usr/local/autoconf-2.69 make sudo make install #### libfcgi git clone https://github.com/toshic/libfcgi
cd libfcgi ./configure make sudo make install
fcgiwrap
Now we need to install fcgiwrap. fcgiwrap is required to passes the request from nginx to thecgit.cgi script as nginx doesn't handle CGI.
git clone git://github.com/gnosek/fcgiwrap.git cd fcgiwrap/
/usr/local/autoconf-2.69/bin/autoreconf -i make sudo make install cgit
Clone the cgit repository.
git clone git://hjemli.net/pub/git/cgit Create a file called cgit.conf in the cgit directory with the following contents
prefix=/usr/local/cgit
CGIT_SCRIPT_PATH=$(prefix)/bin
CGIT_DATA_PATH=$(prefix)/share
Now compile and install cgit as follows. This installs the cgit.cgi at /usr/local/cgit/bin andcgit.png & cgit.css at /usr/local/cgit/share.
cd cgit
git submodule init git submodule update make sudo make install configuration
Now that we have installed nginx, fcgiwrap & cgit, let us configure our setup. Clone my repository if you don't want to type out the following configurations.
Create a file called spawn-fcgi_cgit.conf in the /home/server_config/spawn-fcgi directory with the following contents.
## ABSOLUTE path to the binary FCGIPROGRAM="/usr/local/sbin/fcgiwrap" ## bind to address FCGIADDR="127.0.0.1" ## bind to port FCGIPORT="1026" ## bind to socket FCGISOCKET="/var/run/spawn-fcgi_cgit.socket" ## allowed environment variables sperated by spaces ALLOWED_ENV="PATH USER" ## if this script is run as root switch to the following user USERID=nobody GROUPID=nobody ## write out pid to this file PID_FILE=/var/run/spawn-fcgi_cgit.pid Now let us create a script to automate the start/respawning. Create a file spawn-fcgi_cgit in the /etc/init.d directory with the following contents.
#!/bin/sh # # spawn-fcgi Startup script for the spawn-fcgi process # # chkconfig: - 85 15 # description: FastCGI process launcher for use # # processname: spawn-fcgi # config: /home/server_config/spawn-fcgi/spawn-fcgi_cgit.conf # pidfile: /var/run/spawn-fcgi_cgit.pid # $Id: spawn-fcgi_cgit 2006 2008-05-13 10:56:03Z quwenqing $ # $HeadURL: file:// $ # Source function library . /etc/rc.d/init.d/functions if [ -f /home/server_config/spawn-fcgi/spawn-fcgi_cgit.conf ]; then . /home/server_config/spawn-fcgi/spawn-fcgi_cgit.conf fi prog="spawn-fcgi_cgit" spawnfcgi="/usr/local/bin/spawn-fcgi" RETVAL=0 start() { echo -n $"Starting $prog: " EX="${spawnfcgi} -s ${FCGISOCKET} -u ${USERID} -g ${GROUPID} -P ${PID_FILE} -- ${FCGIPROGRAM}" # -P ${PID_FILE} > /dev/null 2>&1" # copy the allowed environment variables ALLOWED_ENV="$ALLOWED_ENV " unset E for i in ${ALLOWED_ENV}; do E="${E} ${i}=${!i}" done # clean environment and set up a new one daemon env - ${E} ${EX} RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc $prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog && rm -f ${FCGISOCKET} return $RETVAL } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 3 #killall -9 php-cgi start ;; condrestart) if [ -f /var/lock/subsys/$prog ]; then stop start fi ;; status) status $spawnfcgi RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esac exit $RETVAL Make it executable and mark it to start at system boot.
sudo chmod +x /etc/init.d/spawn-fcgi_cgit sudo chkconfig --add spawn-fcgi_cgit sudo chkconfig spawn-fcgi_cgit on Now create the nginx configuration for cgit. Create the file gitweb.conf in the /home/server_config/nginx/include directory with the following contents.
server { listen 80; server_name gitweb.quwenqing.com; rewrite ^/([^?/]+/[^?]*)?(?:?(.*))?$ /cgit.cgi?url=$1&$2 last; location = /favicon.ico { return 200; } location / { root /data/git_repo; index cgit.cgi; } location ~* .cgi$ { gzip off; root /data/git_repo; fastcgi_pass unix:/var/run/spawn-fcgi_cgit.socket; include fastcgi_params; } } cgit requires a configuration file, /etc/cgitrc to inform it of the repositories and other configuration. So create a file cgitrc in the /etc directory with the following content.
# Url which will be used as root for all cgit links virtual-root=/ # Url which specifies the source of an image which will be used as a logo on all cgit pages logo=/cgit.png # Url which specifies the css document to include in all cgit pages css=/cgit.css # Repository configuration repo.url=xxx.git repo.path=/data/git_repo/xxx.git repo.desc=xxx Repo Here I have mirrored the xxx repository to /data/git_repo/xxx.git and added that in the configuration. Lets go ahead and do that to complete the configuration.
sudo mkdir -p /data/git_repo sudo chmod ugo+rwx /data/git_repo cd /data/git_repo git clone http://xxx.net/git/xxx sudo chown -R nobody.nobody /data/git_repo You could also create a new user to administer the repositories instead of giving everyone write permission to /data/git_repo.
Now restart nginx and start cgit-fastcgi to get the web interface running athttp://gitweb.quwenqing.com/.
sudo service nginx restart sudo service spawn-fcgi_cgit start
订阅
上一篇
返回
下一篇
标签:


git命令行与OpenSSH (2015-03-06 11:23)
nginx 同一个IP上配置多个HTTPS主机 (2014-09-03 19:13)
将git库push到另一个远程非22端口库 (2014-03-19 13:43)
nginx模块LuaJIT编译安装问题解决 (2013-03-19 11:19)
安装gitolite (2013-03-13 17:41)
CentOS6上安装部署git1.8 (2013-03-13 15:49)
nginx如何处理web请求 (2012-11-09 22:11)
CentOS下Nginx支持CGI (2012-04-13 13:38)
nginx 漏洞 (2011-08-26 10:52)