3. nginx配置. yum安装的nginx已经默认配置了WebDAV模块,所以不用麻烦了.如果发现没有WebDAV模块的功能,可以参考nginx的官方文档中Dynamic Modules的说明:
(1). 创建授权文件夹以及git的nginx设置文件
> mkdir -p /usr/local/nginx/config > vi /etc/nginx/conf.d/git.conf
内容如下:
server { listen 80; server_name gitServer; root /usr/local/share/gitweb; client_max_body_size 100m; auth_basic "Git User Authentication"; auth_basic_user_file /usr/local/nginx/config/pass.db; location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { root /data/git; } location ~ /.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { root /data/git; fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_connect_timeout 24h; fastcgi_read_timeout 24h; fastcgi_send_timeout 24h; fastcgi_param SCRIPT_FILENAME /usr/local/libexec/git-core/git-http-backend; fastcgi_param PATH_INFO $uri; fastcgi_param GIT_HTTP_EXPORT_ALL ""; fastcgi_param GIT_PROJECT_ROOT /data/git; fastcgi_param REMOTE_USER $remote_user; include fastcgi_params; } try_files $uri @gitweb; location @gitweb { fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_param GITWEB_CONFIG /etc/git/gitweb.conf; fastcgi_param SCRIPT_FILENAME /usr/local/share/gitweb/gitweb.cgi; fastcgi_param PATH_INFO $uri; include fastcgi_params; } }
(2). 修改/etc/nginx/nginx.conf中的worker进程所有者.
# 将此处的nginx用户修改为git用户,以保证能调用到fastcgi(需要和fcgiwrap脚本中的FCGI_USER保持一致)
user git;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid
/var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include
/etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile
on;
#tcp_nopush
on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
4. 安装http-tools并添加认证用户
> yum -y install httpd-tools
> cd /usr/local/nginx/config
> htpasswd -c pass.db guestUser
> git config --global color.ui true
> git config --global user.name 'git'
> git config --global user.email 'example@example.com'
5. 配置gitweb,首先要确定默认安装的gitweb(采用源码安装git才会有)是否存在
> find /usr/local/share -name gitweb.cgi > cd /usr/local/share/gitweb && ll /usr/local/share/gitweb > vi /etc/git/gitweb.conf
gitweb.conf的配置内容如下:
# path to git projects (<project>.git) $projectroot = "/data/git"; # directory to use for temp files $git_temp = "/tmp"; # target of the home link on top of all pages $home_link = $my_uri || "/"; # html text to include at home page $home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. $projects_list = $projectroot; # Javascript code for gitweb $javascript = "static/gitweb.js"; # stylesheet to use $stylesheet = "static/gitweb.css"; # logo to use $logo = "static/git-logo.png"; # the 'favicon' $favicon = "static/git-favicon.png";
三. 启动nginx,fastcgi
> nginx -t > systemctl start nginx > /etc/init.d/fcgiwrap start
四. 问题收集:
1. 访问出现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
五. Gitweb-theme 样式
如果觉得 gitweb 默认样式不好看,可以拿该样式替换