安装nginx
1.如果没有nginx的yum源文件,则编辑repo文件
1
2
3
4
5
6
7vi /etc/yum.repos.d/nginx.repo
#内容如下
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64/
gpgcheck=0
enabled=12.退出保存,使用yum安装nginx
1
yum install nginx -y
下载git并安装,不推荐使用yum安装git,版本过低,到github下载源代码安装
1
2
3
4
5
6
7yum -y remove git
yum -y install perl cpio autoconf tk zlib-devel libcurl-devel openssl-devel expat-devel gettext-devel perl-ExtUtils-MakeMaker automake gcc
cd /usr/local/src;
wget https://github.com/git/git/archive/v2.11.1.tar.gz
tar zxf v2.11.1.tar.gz && cd git-2.11.1
autoconf && ./configure && make && make install
git --version
下载spawn-fcgi,fcgi-devel,fcgiwrap并安装
1.到github下载源代码安装spawn-fcgi
1
2
3cd /usr/local/src;
git clone https://github.com/lighttpd/spawn-fcgi.git
cd spawn-fcgi && ./autogen.sh && ./configure && make && make install2.安装fcgi-devel,注意:需要先安装epel源
1
2yum -y install epel-release
yum -y install fcgi-devel3.安装fcgiwrap,git地址
1
2
3cd /usr/local/src
git clone https://github.com/gnosek/fcgiwrap.git
cd fcgiwrap && autoreconf -i && ./configure && make && make install
4.添加git的运行用户,Git仓库初始化
1 | useradd -r -s /sbin/nologin git |
5.编写fcgiwrap启动脚本
1 | vi /etc/init.d/fcgiwrap |
注意其中的"FCGI_USER" 和 "FCGI_GROUP" 以及 "FORK_NUM",分别为fastcgi运行的用户,组以及进程数(按需调整),需要与nginx配置中的worker用户一样。
修改脚本权限,设置开机启动
1 | chmod a+x /etc/init.d/fcgiwrap |
nginx配置文件内容
1 | server { |
2.修改/etc/nginx/nginx.conf中的worker进程所有者
1 | user git; #将原本的nginx用户改为git用户,确认能调用fastcgi |
7.安装http-tools并添加认证用户
1 | yum -y install httpd-tools |
8.配置gitweb
1 | find /usr/local/share --name gitweb.cgi |
配置内容
1 | # path to git projects (<project>.git) |
9.重启nginx,fastccgi
1 | /usr/sbin/nginx -t |
10.问题
1. 访问http://hostname/repo.git出现502错误,nginx错误日志中出现:connect() to unix:/var/run/fcgiwrap.socket failed (13: Permission denied) while connecting to upstream
解决方法: 检查selinux是否开启,如果开启,请关闭或者配置策略使其能被访问.
2. Can’t locate CPAN.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendorperl /usr/share/perl5/vendorperl /usr/lib/perl5 /usr/share/perl5 .) BEGIN failed–compilation aborted.
解决方法: yum -y install perl-CPAN
3. Can’t locate CGI.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendorperl /usr/share/perl5/vendorperl /usr/lib/perl5 /usr/share/perl5 .) BEGIN failed–compilation aborted.
解决方法: yum -y install perl-CGI
4. Can’t locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/gitweb/gitweb.cgi line 20.
解决方法: yum -y install perl-Time-HiRes
11.修改gitweb-theme样式
cd /usr/local/src
git clone https://github.com/kogakure/gitweb-theme.git
cd gitweb-theme #-t 指定gitweb根目录,一路y即可
./setup -vi -t /usr/local/share/gitweb --install