一、安装gitweb
sudo apt-get install gitweb
二、配置gitweb
vim /etc/gitweb.conf
#Git库所处路径
$projectroot = "/home/simba/git-repo";
#启用追溯
$feature {'blame'}{'default'} = [1];
$feature {'blame'}{'override'} = 1;
#启用快照(snapshot)下载
$feature {'snapshot'}{'default'} = ['zip', 'tgz'];
$feature {'snapshot'}{'override'} = 1;
三、安装fastcgi
nginx 不支持cgi,但可以用fastcgi 代替,详细信息可以自己查查
sudo apt-get install spawn-fcgi fcgiwrap
spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/sbin/fcgiwrap
四、修改Nginx配置文件
#add by lvjiong
server {
listen 8080;
server_name gerrit.cloudwalk.work;
root /usr/share/nginx/html/gitweb;
# root /usr/share/nginx/html;
large_client_header_buffers 4 128k;
client_max_body_size 300m;
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
location /index.cgi {
root /usr/share/gitweb/;
include fastcgi_params;
gzip off;
#fastcgi_pass 127.0.0.1:9001
#fastcgi_param SCRIPT_NAME $uri;
fastcgi_param SCRIPT_NAME /usr/share/gitweb/gitweb.cgi;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# fastcgi_index index.cgi
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location / {
root /usr/share/gitweb/;
index index.cgi;
}
}
五、重启nginx
sudo service nginx restart
六、访问服务器
配置流程相对简单,而且网上也很多,基本都一样。本以为可以正常访问,但是却报错
403 Forbidden 或 502 bad gateway。根据错误log 网上找不到任何有用信息,难道其他人都没遇到?
但是却报502错误,error log如下:
FastCGI sent in stderr: "Can't locate CGI.pm in @INC (you may need to install the CGI module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/gitweb/index.cgi line 13
BEGIN failed--compilation aborted at /usr/share/gitweb/index.cgi line 13" while reading response header from upstream, client: 10.131.0.215, server: gerrit.cloudwalk.work, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "10.131.10.100:8080"
2019/06/28 10:55:19 [error] 23337#23337: *18 upstream prematurely closed FastCGI stdout while reading response header from upstream, client: 10.131.0.215, server: gerrit.cloudwalk.work, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "10.131.10.100:8080"
经过多次尝试,看到一个相似的问题,本来不报希望,没想到却解决了我的问题,安装libcgi-session-perl后正常访问
解决错误
apt-get install libcgi-session-perl
安装nginx + gitweb 参考:https://blog.csdn.net/yuleslie/article/details/8827971
nginx 支持CGI参考 :https://blog.csdn.net/yuleslie/article/details/8827321
502错误排查:https://blog.csdn.net/qq_38256963/article/details/81565722
https://www.cnblogs.com/feng18/p/5148985.html
根据log 排查参考:https://www.linuxquestions.org/questions/programming-9/perl-cgi-can%27t-locate-cgi-pm-330706/