Install the required packages
sudo apt install nginx fcgiwrap apache2-utils -y
nginx: is needed as the webserver
fcgiwrap: will be our interface to the git-http-backend
apache2-utils: is needed to generate the password hash for authentication
Configure the repository
su git
cd /home/git
mkdir repo
cd repo
git init . --bare --shared
git update-server-info
touch git-daemon-export-ok
Enable git push
git config http.receivepack true
Configuring Nginx
su root
vi /etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/git;
server_name _;
location ~ (/.*) {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.gitpasswd;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_PROJECT_ROOT /home/git;
fastcgi_param PATH_INFO $1;
}
}
Generating the password hash
htpasswd -c /etc/nginx/.gitpasswd git
Starting services
change fcgiwrap nginx user group to git
sudo vim /etc/nginx/nginx.conf
sudo vim /lib/systemd/system/fcgiwrap.service
sudo nginx -t
# Make sure these services start on boot
sudo systtemctl enable fcgiwrap
sudo systtemctl enable nginx
# Start them now
sudo systtemctl start fcgiwrap
sudo systtemctl start nginx
Let’s test it
git clone http://git:password@hostname/repo