Skip to content

Instantly share code, notes, and snippets.

@baijian
Last active December 15, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baijian/5337702 to your computer and use it in GitHub Desktop.
Save baijian/5337702 to your computer and use it in GitHub Desktop.
```
sudo apt-get install build-essential autoconf automake \
libtool libfcgi-dev spawn-fcgi \
libssl-dev nginx git-core
```
###fcgiwrap
```
git clone https://github.com/gnosek/fcgiwrap.git
cd fcgiwrap/
autoreconf -i
./configure
make
sudo make install
cp fcgiwrap /usr/bin/
```
###setup spawn-fcgi
(删除原来的/usr/bin/spawn-fcgi,用下面的perl脚本代替)
/usr/bin/spawn-fcgi
contents: /usr/bin/spawn-fcgi which will create a socket to pass .cgi to it
chmod +x /usr/bin/spawn-fcgi
```perl
#!/usr/bin/perl
use strict;
use warnings FATAL => qw( all );
use IO::Socket::UNIX;
my $bin_path = '/usr/bin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;
close STDIN;
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
Local => $socket_path,
Listen => 100,
);
die "Cannot create socket at $socket_path: $!\n" unless $socket;
for (1 .. $num_children) {
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
next if $pid;
exec $bin_path;
die "Failed to exec $bin_path: $!\n";
}
```
###setup /etc/init.d/spawn-fcgi
will be use to automate the respawning of FastCGI(fcgi) socket
chmod +x /etc/init.d/spawn-fcgi
sudo /etc/init.d/spawn-fcgi start
```bash
#!/bin/bash
C_SCRIPT=/usr/bin/spawn-fcgi
USER=www-data
GROUP=www-data
RETVAL=0
case "$1" in
start)
echo "Starting fastcgi"
sudo -u $USER $C_SCRIPT
chown $USER:$GROUP /tmp/cgi.sock
RETVAL=$?
;;
stop)
echo "Stopping fastcgi"
killall -9 fcgiwrap
RETVAL=$?
;;
restart)
echo "Restarting fastcgi"
killall -9 fcgiwrap
$sudo -u $USER $C_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
```
###Install cgit
```
git clone git://github.com/metajack/cgit.git
cd cgit/
git submodule init
git submodule update
make
sudo make install
```
when execute make, you need to install libcurl4-gnutls-dev, not libcurl4-openssl-dev ....
Then you should add /etc/cgitrc, content:
```
virtual-root=/
root-title=GitOnion
root-desc=begin git life
logo=/htdocs/cgit/cgit.png
snapshots=tar.gz tar.bz2 zip
repo.url=project
repo.path=/home/git/repositories/project.git
repo.desc=test
repo.owner=jian.baij@gmail.com
#
#repo.url=project2
#repo.path=/home/git/repositories/project.git
#repo.desc=test2
#repo.owner=jian.baij@gmail.com
#project-list=/home/git/projects.list
#scan-path=/home/git/repositories
```
###Install nginx
at last , you should config your nginx:
```
server {
listen 80;
server_name git.joinjoy.me;
location ~* ^.+\.(css|png|ico)$ {
root /var/www/htdocs/cgit;
expires 30d;
}
location / {
fastcgi_pass unix:/tmp/cgi.sock;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs/cgit/cgit.cgi;
fastcgi_param PATH_INFO $uri;
fastcgi_param QUERY_STRING $args;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
}
```
OK, Start you nginx, then view your cgit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment