Setting up a Git HTTP server with Nginx

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值