Use nginx to build a git server for http access

Generally, after the git installation is completed, the ssh protocol is used to pull and push the git server. If you need to use the http protocol, you need an http container and additional configuration. Here, nginx is used as the http container.

First, you need to install git and nginx , and then you need to install libfcgi-dev, autoconf, libtool, and automake. For the specific process, please refer to https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/

If you want to install through source code, you need to download the corresponding source code, here is the source code path

libfcgi source code , autoconf source code , libtool source code , automake source code

Note that if fcgio.cpp:50:14: error:'EOF' was not declared in this scope overflow(EOF) error occurs when libfcgi is installed, you need to add #include <stdio.h>, fcgio.cpp in front of fcgio.cpp In the libfcgi directory

The    installation process in https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/ mainly has the following points to note

1. You need to install pkg-config before installing fcgiwrap

 pkg-config source code

Installation method

./configure --with-internal-glib
make
make install

2. The bin path of the startup script must be correct, and don't forget to give the script execution permission

我的fcgiwrap在/usr/local/sbin/目录下,所以 $bin_path修改为$bin_path='/usr/local/sbin/fcgiwrap'

3. Put the startup script under rc.local so that it will automatically start every time you boot

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/usr/local/sbin/sshd
/usr/local/nginx/sbin/nginx
/etc/init.d/fcgiwrap
exit 0

Now execute this script

root@ubuntu:/# /etc/init.d/fcgiwrap 
root@ubuntu:/#
root@ubuntu:/# ps aux | grep fcg
root       2174  0.0  0.1   6444  1324 pts/1    S    15:59   0:00 /usr/local/sbin/fcgiwrap
root      14500  0.0  0.0   6444   672 pts/1    S    16:58   0:00 /usr/local/sbin/fcgiwrap
root      14502  0.0  0.2  15956  2228 pts/1    S+   16:59   0:00 grep --color=auto fcg
root@ubuntu:/#

After startup, the cgi.sock file will be generated in the /tmp directory. Note that the startup user is root.

The installation is complete, now you need to configure nginx

Add the following configuration to the nginx.conf file in the conf directory

 server {
        listen      8000;
        server_name localhost;
        root /home/git/repo;

        client_max_body_size 100m;

        auth_basic "git";
        auth_basic_user_file /usr/local/nginx/conf/pass.db;

        location ~(/.*) {
           fastcgi_pass  unix:/tmp/cgi.sock;
           fastcgi_param SCRIPT_FILENAME   /usr/local/libexec/git-core/git-http-backend;
           fastcgi_param PATH_INFO         $1;
           fastcgi_param GIT_HTTP_EXPORT_ALL "";
           fastcgi_param GIT_PROJECT_ROOT  /home/git/repo;
           fastcgi_param REMOTE_USER $remote_user;
           include fastcgi_params;
        }
     }

listen 8000 means listening on port 8000

server_name localhost represents the domain name localhost

root /home/git/repo means that the requested path will be matched under /home/git/repo

For example , the directory matched by http://localhost:8000/blog.git is /home/git/repo/blog.git

auth_basic "git" means that the username is verified as git (if verification is not required, fill in off)

auth_basic_user_file /usr/local/nginx/conf/pass.db is the key file generated by htpasswd for git and its password. If htpasswd is not installed, you can use online generation and copy the file here (please fill in off if you don’t need to verify)

Generate URL online http://tool.oschina.net/htpasswd

 

 

root@ubuntu:/usr/local/nginx/conf# echo "git:AWoU4Acdd8XLM" >> pass.db
root@ubuntu:/usr/local/nginx/conf#

The other thing to note is fastcgi_param SCRIPT_FILENAME /usr/local/libexec/git-core/git-http-backend. If the path is correct, if you don’t know where git-http-backend is, you can look it up.

fastcgi_pass unix:/tmp/cgi.sock is the file path generated after executing the startup script before

Save the file and restart nginx

root@ubuntu:/usr/local/nginx/conf# ps aux | grep nginx
root       2229  0.0  0.0  22444   456 ?        Ss   16:11   0:00 nginx: master process ../sbin/nginx
root       2230  0.0  0.3  22836  3052 ?        S    16:11   0:00 nginx: worker process
root      14546  0.0  0.2  15956  2172 pts/1    S+   17:23   0:00 grep --color=auto nginx
root@ubuntu:/usr/local/nginx/conf#

Note that the worker process user is root, nginx defaults to nobody, modify the configuration nginx.conf

Add to the first line

#user  nobody;
user  root;
worker_processes  1;

Restart, now you can use http protocol for git related operations

Administrator@WL /d/workspace/wl/study/service/email-service (master)
$ git clone http://192.168.245.128:8000/blog.git
Cloning into 'blog'...
Username for 'http://192.168.245.128:8000': git
Password for 'http://[email protected]:8000':
remote: Counting objects: 2312, done.
remote: Compressing objects: 100% (1573/1573), done.
remote: Total 2312 (delta 680), reused 2114 (delta 594)R
Receiving objects: 100% (2312/2312), 8.88 MiB | 0 bytes/s, done.
Resolving deltas: 100% (680/680), done.

Reference https://blog.csdn.net/bb2210083/article/details/82455747 

       https://www.howtoforge.com/tutorial/ubuntu-git-server-installation/

Guess you like

Origin blog.csdn.net/name_is_wl/article/details/86705032