Configure Nginx Git server on Ubuntu system

Configure Nginx Git server on Ubuntu system#

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.

Install git-core, nginx and fcgiwrap

Enter the following commands to install the three required packages:

apt-get install git-core nginx fcgiwrap

Configure nginx

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;}

Create nginx authentication user file##

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.

Create a git code repository##

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

Restart nginx and test##

Enter the command to restart nginx and test the git service:

nginx -s reload
git clone https://server-name/git/test.git

Recommended Posts

Configure Nginx Git server on Ubuntu system
Configure tomcat on ubuntu server
ubuntu install nginx server
Configure Wolfram Engine on Tencent Cloud ubuntu server
Configure automatic updates for Ubuntu Server on Azure
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Install and configure Mono production environment on Ubuntu Server
Install Nginx server on CentOS 7
How to open https on nginx server under Ubuntu
Teach you how to build a Git server on Ubuntu
Build Nginx-RTMP live server on ubuntu
How to install Nginx on Ubuntu 20.04
Turn on Wifi on laptop Ubuntu system
How to install Git on Ubuntu 20.04
Install and configure MySQL on Ubuntu
How to install Git on Ubuntu 20.04
How to secure Nginx on Ubuntu 14.04
How to install Nginx on Ubuntu 20.04
Build a file server on ubuntu
How to install Nginx on Ubuntu 16.04
Install Hadoop system environment on Ubuntu 18.04
Configure ring after installation on Ubuntu 16.04
Install Oracle 11gR2 on Ubuntu Server 12.4.0
Install Gnome and VNC on Ubuntu Server
Configure Nginx load balancing based on CentOS 7
Configure Nginx forward proxy based on CentOS 7
How to install Bacula Server on Ubuntu 14.04
How to configure Redis cluster on Ubuntu 14.04
How to configure Redis replication on Ubuntu 16.04
Deploy python3 and nginx projects on ubuntu18.04
Configure Nginx + PHP 7.0 + MySQL environment under Ubuntu 16.04
How to install Zabbix on Ubuntu 16.04 Server
How to install Squid proxy server on Ubuntu 18.04
How to set up Shiny Server on Ubuntu 14.04
How to install and configure NATS on Ubuntu 16.04
How to set static IP on Ubuntu 18.04 Server
How to install and configure Gogs on Ubuntu 18.04
How to install and configure Cyberpanel on Ubuntu 18.04
How to set static IP on Ubuntu 18.04 Server
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
Install and use Git and GitHub on Ubuntu Linux
How to install and configure GitLab on Ubuntu 18.04
How to install and configure Ansible on Ubuntu 18.04
How to quickly deploy docker on ubuntu server
Configure Nginx to start automatically based on CentOS 7
lamp on ubuntu
How to install and configure Elasticsearch on Ubuntu 16.04
Ubuntu configure Tomcat
How to install and configure PostGIS on Ubuntu 14.04
[Practice] How to install python3.6 on Ubuntu system
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
Ubuntu system installation
How to configure /var/log/messages in Ubuntu system log
Ubuntu configure Apache
How to run the parsing server on Ubuntu 14.04
How to install Git on Ubuntu 18.04 [Quick Start]
How to add logging module to Nginx on Ubuntu 16.04
How to configure Apache content caching on Ubuntu 14.04