Setup a private http/nginx based GIT server

Source: Internet
Author: User
Tags git client

Original: http://aaba.me/blog/2014/03/setup-a-private-http-nginx-based-git-server.html

Https://doomzhou.github.io/git/linux/2016/03/30/git-over-http-by-nginx.html

Reference: http://beginor.github.io/2016/03/12/http-git-server-on-nginx.html

? Downgrade Lightroom 5 Catalog back to Lightroom 4 | Home | Dynamic evaluation of the JSP tag property?

March, 2014Setup a private http/nginx based GIT server

To build a private git server, we don't need much:

    • HTTP access, using Nginx
    • Web browsing Interface
    • Simple HTTP Base Validation

The operating system for a certain release of Debian, a lot of irrelevant details will be skipped, there will be some simple nginx fastcgi configuration instructions.

A lot of information has been found to draw these conclusions:

    • Supports client access with Git-http-backend and supports smart HTTP protocol
    • Use Gitweb to support browser access
    • The above two modules are common CGI and need to be packaged into a fast-cgi with Fcgiwrap
    • Can use Nginx's fast-cgi support
    • Nginx fast-cgi is the proxy, the real fastcgi process needs to be started using spawn-fcgi

Start spawn-fcgi

This specifies the listening port (9001), the process (2, which can be increased according to the actual need), and the last parameter is the location of the Fcgiwrap

Spawn-fcgi-a 127.0.0.1-p 9001-f 2/usr/local/sbin/fcgiwrap
Debian default Fcgiwrap seems to have some problems, according to other people's [experience] (http://stackoverflow.com/questions/14304922/ Nginx-fcgiwrapper-error-cannot-get-script-name) installed one of its own. The fcgiwrap process that starts here listens on the 9001 port, Nginx uses the FASTCGI protocol and they interact, the real script that executes is passed through the fcgi parameter, it will be configured later. * * Install git, gitweb, create git directory * *
Mkdir/data/git
Modify/etc/gitweb.conf, Gitweb need to know where to put the code
# Path to git projects (. git) $projectroot = "/data/git";
* * Configure the Auth_basic_user_file file mentioned in the nginx** configuration file, which can be generated with htpasswd (APACHE2)
server {Listen 80;    server_name my_git_server.com; # Gitweb's non-CGI resource location ~ \.    (PNG|CSS|JS) $ {root/usr/share/gitweb;        } # Gitweb Location/gitweb {auth_basic "Restricted";        AUTH_BASIC_USER_FILE/PATH_TO_PASSWD;        # Fcgiwrap is set up to listen on this host:port fastcgi_pass 127.0.0.1:9001;        Include Fastcgi_params;    # Fcgiwrapper Execute this file Fastcgi_param script_filename/usr/share/gitweb/index.cgi;        } # Git client location/{auth_basic "Restricted";        AUTH_BASIC_USER_FILE/PATH_TO_PASSWD;        # Fcgiwrap is set up to listen on this host:port fastcgi_pass 127.0.0.1:9001;        Include Fastcgi_params;        # Fcgiwrapper Execute this file Fastcgi_param script_filename/usr/lib/git-core/git-http-backend;        # Export all repositories under Git_project_root fastcgi_param git_http_export_all ""; # GIT directory Fastcgi_param git_project_root/data/git;        Fastcgi_param Path_info $;     # Put the user on, or push will fail Fastcgi_param remote_user $remote _user; }}

Follow the above steps, a basic available git is ready, if you encounter some problems, for example, access to Gitweb return 403 error, generally appear in the execution of Fcgiwrapper, can be spawn-fcgi using the-n parameter to start, see error output.

New Project

In the/data/git directory

$ mkdir my-new-repo.git$ cd my-new-repo.git$ git--bare init

Switch to Gitweb and you can see it. If you want to commit the code, remember to check that the user who started spawn-fcgi to have write/data/git directory permissions.

--------------------------------------------------------------------------------------------------------------- ------------------------------

Configuring Nginx Git Server on Ubuntu system

Many years ago I published a blog post that configures Apache git server on a Windows system, primarily with Apache's Basic authentication + git-http-backend, and now needs to deploy a similar simple Git server on the company's VPS. This time the software environment is as follows:

    • Ubuntu 14.04.4 LTS
    • nginx/1.4.6 (Ubuntu)
    • git version 1.9.1

The git-http-backend principle of building a git service is similar, primarily by using a Web server (Apache/nginx) for user authentication and passing user information to a CGI program git-http-backend , which enables GIT operations to be done over HTTP.

Installation of Git-core, Nginx and Fcgiwrap

Enter the following command to install the required three packages:

apt-get install git-core nginx fcgiwrap
Configure Nginx

My goal is to add a virtual directory under Nginx's default Web site and access /git/ /git/xxx.git the code base on the server by accessing xxx.git it, which requires modifying the configuration file of the Nginx Default Web site /etc/nginx/sites-available/default and adding the following information:

# Configure a virtual directory to start with/gitLocation~/git (/.*) {# Use Basic AuthenticationAuth_basic"Restricted";# Certified User FilesAUTH_BASIC_USER_FILE/ETC/NGINX/PASSWD;# FastCGI ParametersFastcgi_pass Unix:/var/run/fcgiwrap.socket; Fastcgi_param Script_filename/usr/lib/git-core/git-http-backend; fastcgi_param git_http_export_all ""; # git repository on the server with directory Fastcgi_param Git_project_root/var/git-repos; Fastcgi_param path_info $ ; # Pass the authenticated user information to the FASTCGI program fastcgi_param remote_user $remote _user; # includes the default fastcgi parameters; include fastcgi_params; # will allow the maximum value of client post to be adjusted to 100 Gigabit max_client_body_size 100M;}         
Create Nginx authenticated user files

Refer to Nginx ngx http auth Basic module, the user authentication file format is as follows:

commentname1:password1name2:password2:commentname3:password3

You can use the htpasswd command to create a user, if the server does not have this command, you can enter a command apt-get install apache2-utils to install the command, after installing this command, you can use it to create authentication users, such as to create a user user1, enter the command as follows:

htpasswd /etc/nginx/passwd user1

Then follow the prompts to enter the password.

Creating a Git code base

The git and directory configured above /var/git-repos , we initialize an empty code base under this directory, the command is as follows:

cd /var/git-reposgit init --bare test.git

Note Check the permissions of the Test.git, if the permissions are insufficient, use this command to set permissions:

test.git
Restart Nginx and test

Enter the command to restart Nginx and test the GIT service:

-s reloadgit clone http://server-name/git/test.git

Setup a private http/nginx based GIT server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.