I published a blog post on Configuring Apache Git Server on Windows System many years ago. It was mainly implemented with Apache’s Basic authentication + git-http-backend. Now we need to deploy a similar simple one on the company’s vps git server, the software environment this time is as follows:
The principle of using git-http-backend
to build a git service is similar, mainly using the web server (apache/nginx) for user authentication and passing user information to the CGI program git-http-backend
to achieve Complete git operation via http.
Enter the following commands to install the three required packages:
apt-get install git-core nginx fcgiwrap
My purpose is to add a virtual directory /git/
under the default website of nginx, and access the xxx.git
code base on the server by accessing the form of /git/xxx.git
, which needs to be modified nginx default website configuration file /etc/nginx/sites-available/default
, add the following information:
# Configured with/Virtual directory starting with git
location ~/git(/.*){
# Use Basic authentication
auth_basic "Restricted";
# Authenticated user file
auth_basic_user_file /etc/nginx/passwd;
# FastCGI parameters
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
# The root directory of the git library on the server
fastcgi_param GIT_PROJECT_ROOT /var/git-repos;
fastcgi_param PATH_INFO $1;
# Pass the authenticated user information to the fastcgi program
fastcgi_param REMOTE_USER $remote_user;
# Include the default fastcgi parameters;
include fastcgi_params;
# Adjust the maximum allowable client post to 100 megabytes
max_client_body_size 100M;}
Refer to nginx ngx http auth basic module, the user authentication file format is as follows:
# comment
name1:password1
name2:password2:comment
name3:password3
You can use the htpasswd
command to create a user. If there is no such command on the server, you can enter the command apt-get install apache2-utils
to install this command. After installing this command, you can use it to create an authenticated user. For example, to create user user1, enter the command as follows:
htpasswd /etc/nginx/passwd user1
Then enter the password as prompted.
The git and directory configured above is /var/git-repos
, we initialize an empty code base in this directory, the command is as follows:
cd /var/git-repos
git init --bare test.git
Pay attention to check the permissions of test.git. If the permissions are insufficient, use this command to set the permissions:
chmod a+rw -R test.git
Enter the command to restart nginx and test the git service:
nginx -s reload
git clone https://server-name/git/test.git
Recommended Posts