Set up gitweb server on nginx

Precondition

please setup your git server via git-http-backend on nginx.

Setup gitweb conf

sudo apt-get install gitweb 
/etc/gitweb.conf is Gitweb (Git web interface) configuration file
The default project root is /usr/lib/git.
Here, I changed to my own path.
our $projectroot = "/home/errong_leng/www/git";

Change nginx conf

cat /etc/nginx/sites-enabled/git.errong.win.conf
server {
    listen  80;
    listen [::]:80;
    server_name git.errong.win;
    auth_basic "Restricted";
    auth_basic_user_file /home/errong_leng/.gitpasswd;
 location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
  root /home/errong_leng/www/git;
  fastcgi_pass unix:/var/run/fcgiwrap.socket;
  fastcgi_param SCRIPT_FILENAME   /usr/lib/git-core/git-http-backend;
  fastcgi_param PATH_INFO         $uri;
  fastcgi_param GIT_PROJECT_ROOT  /home/errong_leng/www/git;
  fastcgi_param GIT_HTTP_EXPORT_ALL "";
  fastcgi_param REMOTE_USER $remote_user;
  include fastcgi_params;
 }
 location /index.cgi {
  root /usr/share/gitweb;
  include fastcgi_params;
  gzip off;
  fastcgi_param SCRIPT_NAME $uri;
  fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
  fastcgi_pass unix:/var/run/fcgiwrap.socket;
 }
 location / {
  root /usr/share/gitweb;
  index index.cgi;
 }
}
cat /etc/nginx/sites-enabled/git.errong.win-ssl.conf
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name git.errong.win;
    ssl_certificate /etc/letsencrypt/git.errong.win/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/git.errong.win/git.errong.win.key;
    auth_basic "Restricted";
    auth_basic_user_file /home/errong_leng/.gitpasswd;
 location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
  root /home/errong_leng/www/git;
  fastcgi_pass unix:/var/run/fcgiwrap.socket;
  fastcgi_param SCRIPT_FILENAME   /usr/lib/git-core/git-http-backend;
  fastcgi_param PATH_INFO         $uri;
  fastcgi_param GIT_PROJECT_ROOT  /home/errong_leng/www/git;
  fastcgi_param GIT_HTTP_EXPORT_ALL "";
  fastcgi_param REMOTE_USER $remote_user;
  include fastcgi_params;
 }
 location /index.cgi {
  root /usr/share/gitweb;
  include fastcgi_params;
  gzip off;
  fastcgi_param SCRIPT_NAME $uri;
  fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
  fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }
 location / {
  root /usr/share/gitweb;
  index index.cgi;
 }
}
Restart nginx server.

gitweb done

git.errong.win

errors handle

If your gitweb server can't work.
You can check the error log to analysis the cause.
cat /var/log/nginx/error.log
In my case, I encountered below errors.
It turned out that my system did not install perl module for CGI and HTML::Entities.
I installed them manually from sources.
Download CGI source
Download HTML::Entities source
I have a post for this. Install perl module from source
2018/06/13 04:35:36 [error] 28827#28827: *6986 FastCGI sent in stderr: "Can't locate CGI.pm in @INC (you may nee
d to install the CGI module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/sh
are/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/s
hare/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/gitweb/index.cgi li
ne 13.
BEGIN failed--compilation aborted at /usr/share/gitweb/index.cgi line 13" while reading response header from ups
tream, client: 58.213.161.114, server: git.errong.win, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var
/run/fcgiwrap.socket:", host: "git.errong.win"
2018/06/13 04:35:36 [error] 28827#28827: *6986 upstream prematurely closed FastCGI stdout while reading response
 header from upstream, client: 58.213.161.114, server: git.errong.win, request: "GET / HTTP/1.1", upstream: "fas
tcgi://unix:/var/run/fcgiwrap.socket:", host: "git.errong.win"


2018/06/13 04:58:03 [error] 28827#28827: *7008 FastCGI sent in stderr: "[Wed Jun 13 04:58:03 2018] index.cgi: Ca
n't locate HTML/Entities.pm in @INC (you may need to install the HTML::Entities module) (@INC contains: /etc/per
l /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/local/share/perl/5.22.1/CGI.pm line 2219" while reading response header from u
pstream, client: 58.213.161.114, server: git.errong.win, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/v
ar/run/fcgiwrap.socket:", host: "git.errong.win"
2018/06/13 04:58:30 [error] 28827#28827: *7010 FastCGI sent in stderr: "[Wed Jun 13 04:58:30 2018] index.cgi: Ca
n't locate HTML/Entities.pm in @INC (you may need to install the HTML::Entities module) (@INC contains: /etc/per
l /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/local/share/perl/5.22.1/CGI.pm line 2219" while reading response header from u
pstream, client: 210.94.41.89, server: git.errong.win, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var
/run/fcgiwrap.socket:", host: "git.errong.win"

No comments:

Post a Comment

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...